def Convert_Special( filepath=xbmc.translatePath('special://home'), string=False, quoted=True): """ Convert physcial paths stored in text files to their special:// equivalent or replace instances of physical paths to special in a string sent through. CODE: Convert_Special([filepath, string]) AVAILABLE PARAMS: filepath - This is the path you want to scan, by default it's set to the Kodi HOME directory. string - By default this is set to False, if you set to True you will get the string of your 'filepath' returned with any reference to physical path replaced with special:// quoted - By default this is set to true, this means the return you get will be converted with urllib.quote_plus(). This is ideal if you need to get a string you can send through as a path for routing. EXAMPLE CODE: path = xbmc.translatePath('special://profile') dialog.ok('[COLOR gold]ORIGINAL PATH[/COLOR]','Let\'s convert this path to it\'s special equivalent:\n[COLOR dodgerblue]%s[/COLOR]'%path) path = Convert_Special(filepath=path,string=True) dialog.ok('[COLOR gold]CONVERTED PATH[/COLOR]','This is the converted path:\n[COLOR dodgerblue]%s[/COLOR]'%path) if dialog.yesno('[COLOR gold]CONVERT PHYSICAL PATHS[/COLOR]','We will now run through your Kodi folder converting all physical paths to their special:// equivalent in xml/hash/properties/ini files.\nDo you want to continue?'): koding.Convert_Special() dialog.ok('[COLOR gold]SUCCESS[/COLOR]','Congratulations, all references to your physical paths have been converted to special:// paths.') ~""" import urllib from filetools import Text_File if not string: for root, dirs, files in os.walk(filepath): for file in files: if file.endswith(".xml") or file.endswith( ".hash") or file.endswith( "properies") or file.endswith(".ini"): contents = Text_File(os.path.join(root, file), 'r') encodedpath = urllib.quote(HOME) encodedpath2 = encodedpath.replace('%3A', '%3a').replace( '%5C', '%5c') newfile = contents.replace(HOME, 'special://home/').replace( encodedpath, 'special://home/').replace( encodedpath2, 'special://home/') Text_File(os.path.join(root, file), 'w', newfile) else: encodedpath = urllib.quote(HOME) encodedpath2 = encodedpath.replace('%3A', '%3a').replace('%5C', '%5c') newstring = filepath.replace(HOME, 'special://home/').replace( encodedpath, 'special://home/').replace(encodedpath2, 'special://home/') if quoted: newstring = urllib.quote_plus(newstring) return newstring
def Convert_Special(filepath=HOME, string=False, quoted=True): """ Convert physcial paths stored in text files to their special:// equivalent or replace instances of physical paths to special in a string sent through. CODE: Convert_Special([filepath, string]) AVAILABLE PARAMS: filepath - This is the path you want to scan, by default it's set to the Kodi HOME directory. string - By default this is set to False which means it will convert all instances found of the physical paths to their special equivalent. The scan will convert all instances in all filenames ending in ini, xml, hash, properties. If you set this value to True you will get a return of your 'filepath' string and no files will be altered. quoted - By default this is set to true, this means the return you get will be converted with urllib.quote_plus(). This is ideal if you need to get a string you can send through as a path for routing. EXAMPLE CODE: path = koding.Physical_Path('special://profile') dialog.ok('ORIGINAL PATH','Let\'s convert this path to it\'s special equivalent:\n[COLOR dodgerblue]%s[/COLOR]'%path) path = Convert_Special(filepath=path,string=True,quoted=False) dialog.ok('CONVERTED PATH','This is the converted path:\n[COLOR dodgerblue]%s[/COLOR]'%path) if dialog.yesno('CONVERT PHYSICAL PATHS','We will now run through your Kodi folder converting all physical paths to their special:// equivalent in xml/hash/properties/ini files.\nDo you want to continue?'): koding.Convert_Special() dialog.ok('SUCCESS','Congratulations, all references to your physical paths have been converted to special:// paths.') ~""" import urllib from filetools import Text_File if not string: for root, dirs, files in os.walk(filepath): for file in files: if file.endswith(".xml") or file.endswith(".hash") or file.endswith("properies") or file.endswith(".ini"): contents = Text_File(os.path.join(root,file), 'r') encodedpath = urllib.quote(HOME) encodedpath2 = encodedpath.replace('%3A','%3a').replace('%5C','%5c') newfile = contents.replace(HOME, 'special://home/').replace(encodedpath, 'special://home/').replace(encodedpath2, 'special://home/') Text_File(os.path.join(root, file), 'w', newfile) else: encodedpath = urllib.quote(HOME) encodedpath2 = encodedpath.replace('%3A','%3a').replace('%5C','%5c') newstring = filepath.replace(HOME, 'special://home/').replace(encodedpath, 'special://home/').replace(encodedpath2, 'special://home/') if quoted: newstring = urllib.quote_plus(newstring) return newstring
def Addon_Service(addons='all', mode='list', skip_service='all'): """ Send through an add-on id, list of id's or leave as the default which is "all". This will loop through the list of add-ons and return the ones which are run as services. This enable/disable feature will comment out the service lines, and does not stop a running service or start a service. This is designed more for if you've manually extracted a new add-on into your system and it isn't yet enabled. Occasionally if the add-ons have dependencies which are run as services then trying to enable them can cause Kodi to freeze. CODE: Addon_Service([addon,disable]) AVAILABLE PARAMS: addons - By default this is set to "all" but if there's a sepcific set of add-ons you want to disable the service for just send through the id's in the form of a list. mode - By default this is set to 'list' meaning you'll get a return of add-on folders which contain an instance of service in the add-on.xml. You can set this to "disable" to comment out the instances of service and similarly when you need to re-enable you can use "enable" and that will uncomment out the service item. Please note that by uncommenting the service will not automatically start - you'll need to reload the profile for that. skip_service - This function can fail if certain dependencies are run as a service, if they are causing problems you can send through the id or a list of id's which you want to disable the service for. This will comment out the service part in the addon.xml before attempting to enable the add-on. Don't forget to re-enable this if you want the service running. EXAMPLE CODE: dialog.ok('[COLOR gold]CHECKING FOR SERVICES[/COLOR]','We will now check for all add-ons installed which contain services') service_addons = Addon_Service(mode='list') my_text = 'List of add-ons running as a service:\n\n' for item in service_addons: my_text += item+'\n' koding.Text_Box('[COLOR gold]SERVICE ADDONS[/COLOR]',my_text) ~""" from filetools import Get_Contents, Text_File from systemtools import Data_Type from guitools import Text_Box service_addons = [] if addons=='all': addons = Get_Contents(path=ADDONS, exclude_list=['packages','temp'],full_path=False) else: if Data_Type(addons) == 'str': addons = [addons] if skip_service=='all': skip_service = addons else: if Data_Type(skip_service) == 'str': skip_service = [skip_service] service_line = '<extension point="xbmc.service"' for item in addons: addon_path = os.path.join(ADDONS,item,'addon.xml') if os.path.exists(addon_path) and item not in skip_service: content = Text_File(addon_path,'r') if service_line in content: xbmc.log('%s contains a service,'%item,2) for line in content.splitlines(): if service_line in line: if item not in service_addons: service_addons.append(item) if not (line.strip().startswith('<!--')) and (mode == 'disable'): replace_line = '<!--%s-->'%line Text_File(addon_path,'w',content.replace(line,replace_line)) break elif line.strip().startswith('<!--') and mode == 'enable': replace_line = line.replace(r'<!--','').replace(r'-->','') Text_File(addon_path,'w',content.replace(line,replace_line)) break return service_addons
def Addon_Service(addons='all', mode='list', skip_service=[]): """ Send through an add-on id, list of id's or leave as the default which is "all". This will loop through the list of add-ons and return the ones which are run as services. This enable/disable feature will comment out the service lines, and does not stop a running service or start a service. This is designed more for if you've manually extracted a new add-on into your system and it isn't yet enabled. Occasionally if the add-ons have dependencies which are run as services then trying to enable them can cause Kodi to freeze. CODE: Addon_Service([addon,disable]) AVAILABLE PARAMS: addons - By default this is set to "all" but if there's a sepcific set of add-ons you want to disable the service for just send through the id's in the form of a list. mode - By default this is set to 'list' meaning you'll get a return of add-on folders which contain an instance of service in the add-on.xml. You can set this to "disable" to comment out the instances of service and similarly when you need to re-enable you can use "enable" and that will uncomment out the service item. Please note that by uncommenting the service will not automatically start - you'll need to reload the profile for that. skip_service - When running the enable or disable mode you can choose to add a list of add-ons you'd like to skip the process for. Of course you may be thinking why would I send through a list of addons I want the service enabled/disabled for but then I also add them to the skip_service list to say DON'T enable/disable - it makes no sense?! Well you'd be correct that doesn't make any sense as presumably you've already filtered out the add-ons you don't want affected, this command is designed more for those who don't send through a list of add-ons and instead use the default "all" value for the addons paramater. This then makes it very easy to just skip a handful of add-on services and enable all others. EXAMPLE CODE: dialog.ok('CHECKING FOR SERVICES','We will now check for all add-ons installed which contain services') service_addons = Addon_Service(mode='list') my_text = 'List of add-ons running as a service:\n\n' for item in service_addons: my_text += item+'\n' koding.Text_Box('[COLOR gold]SERVICE ADDONS[/COLOR]',my_text) ~""" from filetools import Get_Contents, Physical_Path, Text_File from vartools import Data_Type from guitools import Text_Box service_addons = [] if addons == 'all': addons = Get_Contents(path=ADDONS, exclude_list=['packages', 'temp'], full_path=False) else: if Data_Type(addons) == 'str': addons = [addons] if Data_Type(skip_service) == 'str': skip_service = [skip_service] service_line = '<extension point="xbmc.service"' for item in addons: addon_path = os.path.join(ADDONS, item, 'addon.xml') content = Text_File(addon_path, 'r') if service_line in content: if item not in service_addons: service_addons.append(item) if mode != 'list': if not item in skip_service: for line in content.splitlines(): if service_line in line: if not (line.strip().startswith('<!--')) and ( mode == 'disable'): replace_line = '<!--%s-->' % line Text_File( addon_path, 'w', content.replace(line, replace_line)) break elif line.strip().startswith( '<!--') and mode == 'enable': replace_line = line.replace(r'<!--', '').replace( r'-->', '') Text_File( addon_path, 'w', content.replace(line, replace_line)) break return service_addons
def Addon_Service(addons='all', mode='list', skip_service=[]): """ Send through an add-on id, list of id's or leave as the default which is "all". This will loop through the list of add-ons and return the ones which are run as services. This enable/disable feature will comment out the service lines, and does not stop a running service or start a service. This is designed more for if you've manually extracted a new add-on into your system and it isn't yet enabled. Occasionally if the add-ons have dependencies which are run as services then trying to enable them can cause Kodi to freeze. CODE: Addon_Service([addon,disable]) AVAILABLE PARAMS: addons - By default this is set to "all" but if there's a sepcific set of add-ons you want to disable the service for just send through the id's in the form of a list. mode - By default this is set to 'list' meaning you'll get a return of add-on folders which contain an instance of service in the add-on.xml. You can set this to "disable" to comment out the instances of service and similarly when you need to re-enable you can use "enable" and that will uncomment out the service item. Please note that by uncommenting the service will not automatically start - you'll need to reload the profile for that. skip_service - When running the enable or disable mode you can choose to add a list of add-ons you'd like to skip the process for. Of course you may be thinking why would I send through a list of addons I want the service enabled/disabled for but then I also add them to the skip_service list to say DON'T enable/disable - it makes no sense?! Well you'd be correct that doesn't make any sense as presumably you've already filtered out the add-ons you don't want affected, this command is designed more for those who don't send through a list of add-ons and instead use the default "all" value for the addons paramater. This then makes it very easy to just skip a handful of add-on services and enable all others. EXAMPLE CODE: dialog.ok('CHECKING FOR SERVICES','We will now check for all add-ons installed which contain services') service_addons = Addon_Service(mode='list') my_text = 'List of add-ons running as a service:\n\n' for item in service_addons: my_text += item+'\n' koding.Text_Box('[COLOR gold]SERVICE ADDONS[/COLOR]',my_text) ~""" from filetools import Get_Contents, Physical_Path, Text_File from vartools import Data_Type from guitools import Text_Box service_addons = [] if addons=='all': addons = Get_Contents(path=ADDONS, exclude_list=['packages','temp'],full_path=False) else: if Data_Type(addons) == 'str': addons = [addons] if Data_Type(skip_service) == 'str': skip_service = [skip_service] service_line = '<extension point="xbmc.service"' for item in addons: addon_path = os.path.join(ADDONS,item,'addon.xml') content = Text_File(addon_path,'r') if service_line in content: if item not in service_addons: service_addons.append(item) if mode != 'list': if not item in skip_service: for line in content.splitlines(): if service_line in line: if not (line.strip().startswith('<!--')) and (mode == 'disable'): replace_line = '<!--%s-->'%line Text_File(addon_path,'w',content.replace(line,replace_line)) break elif line.strip().startswith('<!--') and mode == 'enable': replace_line = line.replace(r'<!--','').replace(r'-->','') Text_File(addon_path,'w',content.replace(line,replace_line)) break return service_addons