Advertisement
costaplus

Config_old

Jun 18th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.14 KB | None | 0 0
  1. PLATFORM_NAME = "kodi-isengard"
  2. print "streamondemand.core.config PLATFORM_NAME="+PLATFORM_NAME
  3.  
  4. PLUGIN_NAME = "streamondemand"
  5. __settings__ = xbmcaddon.Addon(id="plugin.video."+PLUGIN_NAME)
  6. __language__ = __settings__.getLocalizedString
  7.  
  8. def get_platform():
  9.     return PLATFORM_NAME
  10.  
  11. def is_xbmc():
  12.     return True
  13.  
  14. def get_library_support():
  15.     return True
  16.  
  17. def get_system_platform():
  18.     """ fonction: pour recuperer la platform que xbmc tourne """
  19.     import xbmc
  20.     platform = "unknown"
  21.     if xbmc.getCondVisibility( "system.platform.linux" ):
  22.         platform = "linux"
  23.     elif xbmc.getCondVisibility( "system.platform.xbox" ):
  24.         platform = "xbox"
  25.     elif xbmc.getCondVisibility( "system.platform.windows" ):
  26.         platform = "windows"
  27.     elif xbmc.getCondVisibility( "system.platform.osx" ):
  28.         platform = "osx"
  29.     return platform
  30.  
  31. def open_settings():
  32.     __settings__.openSettings()
  33.  
  34. def get_setting(name):
  35.     return __settings__.getSetting( name )
  36.  
  37. def set_setting(name,value):
  38.     __settings__.setSetting( name,value )
  39.  
  40. def get_localized_string(code):
  41.     dev = __language__(code)
  42.  
  43.     try:
  44.         dev = dev.encode("utf-8")
  45.     except:
  46.         pass
  47.    
  48.     return dev
  49.  
  50. def get_library_path():
  51.  
  52.     if get_system_platform() == "xbox":
  53.         default = xbmc.translatePath(os.path.join(get_runtime_path(),"library"))
  54.     else:
  55.         default = xbmc.translatePath("special://profile/addon_data/plugin.video."+PLUGIN_NAME+"/library")
  56.  
  57.     value = get_setting("librarypath")
  58.     if value=="":
  59.         value=default
  60.  
  61.     return value
  62.  
  63. def get_temp_file(filename):
  64.     return xbmc.translatePath( os.path.join( "special://temp/", filename ))
  65.  
  66. def get_runtime_path():
  67.     return xbmc.translatePath( __settings__.getAddonInfo('Path') )
  68.  
  69. def get_data_path():
  70.     dev = xbmc.translatePath( __settings__.getAddonInfo('Profile') )
  71.    
  72.     # Parche para XBMC4XBOX
  73.     if not os.path.exists(dev):
  74.         os.makedirs(dev)
  75.    
  76.     return dev
  77.  
  78. def get_cookie_data():
  79.     import os
  80.     ficherocookies = os.path.join( get_data_path(), 'cookies.dat' )
  81.  
  82.     cookiedatafile = open(ficherocookies,'r')
  83.     cookiedata = cookiedatafile.read()
  84.     cookiedatafile.close();
  85.  
  86.     return cookiedata
  87.  
  88. # Test if all the required directories are created
  89. def verify_directories_created():
  90.     import logger
  91.     import os
  92.     logger.info("streamondemand.core.config.verify_directories_created")
  93.  
  94.     # Force download path if empty
  95.     download_path = get_setting("downloadpath")
  96.     if download_path=="":
  97.         download_path = os.path.join( get_data_path() , "downloads")
  98.         set_setting("downloadpath" , download_path)
  99.  
  100.     # Force download list path if empty
  101.     download_list_path = get_setting("downloadlistpath")
  102.     if download_list_path=="":
  103.         download_list_path = os.path.join( get_data_path() , "downloads" , "list")
  104.         set_setting("downloadlistpath" , download_list_path)
  105.  
  106.     # Force bookmark path if empty
  107.     bookmark_path = get_setting("bookmarkpath")
  108.     if bookmark_path=="":
  109.         bookmark_path = os.path.join( get_data_path() , "bookmarks")
  110.         set_setting("bookmarkpath" , bookmark_path)
  111.  
  112.     # Create data_path if not exists
  113.     if not os.path.exists(get_data_path()):
  114.         logger.debug("Creating data_path "+get_data_path())
  115.         try:
  116.             os.mkdir(get_data_path())
  117.         except:
  118.             pass
  119.  
  120.     # Create download_path if not exists
  121.     if not download_path.lower().startswith("smb") and not os.path.exists(download_path):
  122.         logger.debug("Creating download_path "+download_path)
  123.         try:
  124.             os.mkdir(download_path)
  125.         except:
  126.             pass
  127.  
  128.     # Create download_list_path if not exists
  129.     if not download_list_path.lower().startswith("smb") and not os.path.exists(download_list_path):
  130.         logger.debug("Creating download_list_path "+download_list_path)
  131.         try:
  132.             os.mkdir(download_list_path)
  133.         except:
  134.             pass
  135.  
  136.     # Create bookmark_path if not exists
  137.     if not bookmark_path.lower().startswith("smb") and not os.path.exists(bookmark_path):
  138.         logger.debug("Creating bookmark_path "+bookmark_path)
  139.         try:
  140.             os.mkdir(bookmark_path)
  141.         except:
  142.             pass
  143.  
  144.     # Create library_path if not exists
  145.     if not get_library_path().lower().startswith("smb") and not os.path.exists(get_library_path()):
  146.         logger.debug("Creating library_path "+get_library_path())
  147.         try:
  148.             os.mkdir(get_library_path())
  149.         except:
  150.             pass
  151.  
  152.     # Checks that a directory "xbmc" is not present on platformcode
  153.     old_xbmc_directory = os.path.join( get_runtime_path() , "platformcode" , "xbmc" )
  154.     if os.path.exists( old_xbmc_directory ):
  155.         logger.debug("Removing old platformcode.xbmc directory")
  156.         try:
  157.             import shutil
  158.             shutil.rmtree(old_xbmc_directory)
  159.         except:
  160.             pass
  161.  
  162. print "streamondemand.core.config runtime path = "+get_runtime_path()
  163. print "streamondemand.core.config data path = "+get_data_path()
  164. print "streamondemand.core.config temp path = "+get_temp_file("test")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement