def __init__(self, addon_id, url, full_name, destination, master=False, quiet=False, installed_list=[], batch=False): self.installed_list = installed_list self.quiet = quiet self.batch=batch if not self.quiet: kodi.open_busy_dialog() v = kodi.get_kodi_version() # Grab a list of KNOWN addons from the database. Unfortunately Jarvis requires direct database access for the installed flag if v >= 17: response = kodi.kodi_json_request("Addons.GetAddons", { "installed": False, "properties": ["path", "dependencies"]}) for a in response['result']['addons']: self.available_addons += [a['addonid']] self.source_table[a['addonid']] = a['path'] else: from sqlite3 import dbapi2 dbf = kodi.vfs.join("special://profile/Database", "Addons20.db") with dbapi2.connect(dbf) as dbh: dbc = dbh.cursor() dbc.execute("SELECT addon.addonID, broken.addonID is Null AS enabled, addon.path FROM addon LEFT JOIN broken on addon.addonID=broken.addonID WHERE enabled=1") for a in dbc.fetchall(): self.available_addons += [a[0]] self.source_table[a[0]] = a[2] dbh.close() self._addon_id = addon_id self._url = url self._full_name = full_name self._user, self.repo = full_name.split("/") self._master = master self._destination = destination # Add the final addon target to the sources list with type of zip # Initiate install routine self.install_addon(addon_id, url, full_name, master) completed = list(reversed(self.completed)) if not quiet: pb = kodi.ProgressBar() pb.new('Enabling Addons', len(completed)+1) pb.update_subheading('Building Addon List') kodi.run_command("XBMC.UpdateLocalAddons()") kodi.sleep(500) for addon_id in completed: if not quiet: #percent = 100* (completed.index(addon_id) / len(completed)) #pb.update(percent, "Enabling Addons", addon_id, '') pb.next(addon_id) kodi.sleep(100) self.enable_addon(addon_id) if not quiet: pb.next("Looking for Updates", "") kodi.sleep(500) kodi.run_command('XBMC.UpdateAddonRepos') # Enable installed addons if not self.quiet: pb.close() kodi.close_busy_dialog() if self.install_error: kodi.notify("Install failed", self._addon_id) else: kodi.notify("Install complete", self._addon_id)
def install_batch(): import xbmcgui from libs import github from libs import github_installer if kodi.mode == 'install_batch': url = kodi.arg('url') xml, zip_ref = github.batch_installer(url) else: url = kodi.dialog_file_browser('Select a install file', mask='.zip') if not github.re_installer.search(url): return xml, zip_ref = github.batch_installer(url, True) if not kodi.dialog_confirm('Batch Installer?', "Click YES to proceed.", "This will install a list of addons.", "Some configuration files and settings may be overwritten."): return if not xml: return # Install each addon as instructed installed_list = [] count = 0 for a in xml.findAll('addon'): count +=1 PB = kodi.ProgressBar() PB.new('Batch Installer - Progress', count) for a in xml.findAll('addon'): addon_id = a.find('addon_id') username = a.find('username') if addon_id is None or username is None: continue username = username.text addon_id = addon_id.text PB.next(addon_id) if not kodi.get_condition_visiblity("System.HasAddon(%s)"% addon_id): if PB.is_canceled(): return kodi.log("Batch install " + addon_id) url, filename, full_name, version = github.find_zip(username, addon_id) installed_list += github_installer.GitHub_Installer(addon_id, url, full_name, kodi.vfs.join("special://home", "addons"), quiet=True, batch=True, installed_list=installed_list).installed_list kodi.sleep(1000) # Look for config files. # Need to add error checking for missing config files configs= xml.find('configs') if configs is not None and 'dir' in configs.attrs[0]: config_dir = configs['dir'] for config in configs.findAll('config'): source = config.find('source') destination = config.find('destination') if source is None or destination is None: continue source = source.text destination = destination.text if not kodi.vfs.exists(destination): kodi.vfs.mkdir(destination, True) kodi.vfs.write_file(kodi.vfs.join(destination, source), zip_ref.read(config_dir + '/' + source)) # Now look for individual setting key and value pairs # Set them as instructed settings= xml.find('settings') if settings is not None: for setting in settings.findAll('setting'): if 'addon_id' in setting.attrs[0]: addon_id = setting['addon_id'] k = setting.find('key') v = setting.find('value') if k is None or v is None: continue kodi.set_setting(k.text, v.text, addon_id) builtins= xml.find('builtins') if builtins is not None: for cmd in builtins.findAll('command'): cmd = cmd.text kodi.run_command(cmd) jsonrpc= xml.find('jsonrpc') if jsonrpc is not None: from ast import literal_eval for cmd in jsonrpc.findAll('command'): method = cmd.find('method').text params = literal_eval(cmd.find('params').text) id = cmd.find('id').text kodi.kodi_json_request(method, params, id) # Now clean up zip_ref.close() PB.close() r = kodi.dialog_confirm(kodi.get_name(), 'Click Continue to install more addons or', 'Restart button to finalize addon installation', yes='Restart', no='Continue') if r: import sys import xbmc if sys.platform in ['linux', 'linux2', 'win32']: xbmc.executebuiltin('RestartApp') else: xbmc.executebuiltin('ShutDown')
def execute_command(): cmd = kodi.arg('xbmc', decode='json') cmd = "%s(%s)" % (cmd['command'], cmd['args']) kodi.run_command(cmd)