def install_package(self, install_style): self.deploy_init() if install_style == None: install_style = tools.showDialog.select( tools.addonName, ['Browse...', 'Web Location...']) else: install_style = int(install_style) if install_style == 0: zip_location = tools.fileBrowser(1, 'Locate Provider Zip', 'files', '.zip', True, False) elif install_style == 1: zip_location = tools.showKeyboard( '', '%s: Enter Zip URL' % tools.addonName) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return else: return zip_file = self.get_zip_file(zip_location) if zip_file is None: return self.install_zip(zip_file)
def _get_zip_location(self): zip_location = None install_type = tools.showDialog.select(tools.addonName, [tools.lang(40302), tools.lang(40303)]) if install_type == -1: return None if install_type == 0: zip_location = tools.fileBrowser(1, tools.lang(40304), 'files', '.zip', True, False) elif install_type == 1: user_input = tools.showKeyboard('', '%s: %s' % (tools.addonName, tools.lang(40305))) user_input.doModal() if user_input.isConfirmed() and user_input.getText() != '': zip_location = user_input.getText() else: return return zip_location
def install_package(self, install_style, url=None): self.deploy_init() if url is None: if install_style is None: install_style = tools.showDialog.select( tools.addonName, [tools.lang(40302), tools.lang(40303)]) else: install_style = int(install_style) if install_style == 0: zip_location = tools.fileBrowser( 1, tools.lang(40304).format('Provider'), 'files', '.zip', True, False) elif install_style == 1: zip_location = tools.showKeyboard( '', '%s: %s' % (tools.addonName, tools.lang(40305))) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return else: return else: zip_location = url if url is not None: zip_file = self.get_zip_file(zip_location, True) else: zip_file = self.get_zip_file(zip_location, False) if zip_file is None: return self.install_zip(zip_file)
def install_zip(install_style): folders = ['providerModules/', 'providers/'] deploy_init() if install_style == None: browse_download = tools.showDialog.select(tools.addonName, [tools.lang(40302), tools.lang(40303)]) if browse_download == 0: zip_location = tools.fileBrowser(1, tools.lang(40304), 'files', '.zip', True, False) elif browse_download == 1: zip_location = tools.showKeyboard('', '%s: %s' % (tools.addonName, tools.lang(40305))) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return else: return else: if install_style == '0': zip_location = tools.fileBrowser(1, tools.lang(40304), 'files', '.zip', True, False) if install_style == '1': zip_location = tools.showKeyboard('', '%s: %s' % (tools.addonName, tools.lang(40305))) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return if zip_location == '': return if zip_location.startswith('smb'): tools.showDialog.ok(tools.addonName, tools.lang(40309)) return if zip_location.startswith('http'): response = requests.get(zip_location, stream=True) if not response.ok: tools.showDialog.ok(tools.addonName, tools.lang(40310)) else: pass try: import StringIO file = zipfile.ZipFile(StringIO.StringIO(response.content)) except: #Python 3 Support import io file = zipfile.ZipFile(io.BytesIO(response.content)) else: file = zipfile.ZipFile(zip_location) file_list = file.namelist() for i in file_list: if i.startswith('/') or '..' in i: raise Exception meta_file = None for i in file_list: if i.startswith('meta.json'): meta_file = i if meta_file is not None: meta = file.open(meta_file) meta = meta.readlines() meta = ''.join(meta) meta = meta.replace(' ', '').replace('\r','').replace('\n','') meta = json.loads(meta) requirements = ['author', 'name', 'version'] for i in requirements: if i not in meta: malformed_output() return author = meta['author'] version = meta['version'] pack_name = meta['name'] else: malformed_output() import traceback traceback.print_exc() raise Exception line1 = tools.colorString('{}: '.format(tools.lang(40311))) + '{} - v{}'.format(pack_name, version) line2 = tools.colorString('{}: '.format(tools.lang(40312))) + "%s" % author line3 = tools.lang(40313) accept = tools.showDialog.yesno("{} - {}".format(tools.addonName, tools.lang(40314)), line1, line2, line3, tools.lang(40315), tools.lang(40316)) if accept == 0: return install_progress = tools.progressDialog install_progress.create(tools.addonName, '%s - %s' % (tools.lang(40317), pack_name), tools.lang(33009)) install_progress.update(-1) try: for folder in folders: for zip_file in file_list: if zip_file.startswith(folder): file.extract(zip_file, tools.dataPath) try: file.close() install_progress.close() except: pass tools.showDialog.ok(tools.addonName, '%s - %s' % (tools.lang(40318), pack_name)) except: import traceback traceback.print_exc() install_progress.close() tools.showDialog.ok(tools.addonName, '%s - %s' % (tools.lang(40319), pack_name), tools.lang(40320)) return customProviders.providers().update_known_providers()
def install_zip(install_style): folders = ['providerModules/', 'providers/'] deploy_init() if install_style == None: browse_download = tools.showDialog.select( tools.addonName, ['Browse...', 'Web Location...']) if browse_download == 0: zip_location = tools.fileBrowser(1, 'Locate Provider Zip', 'files', '.zip', True, False) elif browse_download == 1: zip_location = tools.showKeyboard( '', '%s: Enter Zip URL' % tools.addonName) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return else: return else: if install_style == '0': zip_location = tools.fileBrowser(1, 'Locate Provider Zip', 'files', '.zip', True, False) if install_style == '1': zip_location = tools.showKeyboard( '', '%s: Enter Zip URL' % tools.addonName) zip_location.doModal() if zip_location.isConfirmed() and zip_location.getText() != '': zip_location = zip_location.getText() else: return if zip_location == '': return if zip_location.startswith('smb'): tools.showDialog.ok(tools.addonName, 'Sorry, SMB shares are not supported') return if zip_location.startswith('http'): response = requests.get(zip_location, stream=True) if not response.ok: tools.showDialog.ok( tools.addonName, 'Unable to connect to file.\n' 'Please check URL and try again.') else: pass try: import StringIO file = zipfile.ZipFile(StringIO.StringIO(response.content)) except: #Python 3 Support import io file = zipfile.ZipFile(io.BytesIO(response.content)) else: file = zipfile.ZipFile(zip_location) file_list = file.namelist() for i in file_list: if i.startswith('/') or '..' in i: raise Exception meta_file = None for i in file_list: if i.startswith('meta.json'): meta_file = i if meta_file is not None: meta = file.open(meta_file) meta = meta.readlines() meta = ''.join(meta) meta = meta.replace(' ', '').replace('\r', '').replace('\n', '') meta = json.loads(meta) requirements = ['author', 'name', 'version'] for i in requirements: if i not in meta: malformed_output() return author = meta['author'] version = meta['version'] pack_name = meta['name'] else: malformed_output() import traceback traceback.print_exc() raise Exception line1 = tools.colorString('Installing:') + " %s - v%s" % (pack_name, version) line2 = tools.colorString("Author: ") + "%s" % author line3 = "Are you sure you wish to proceed?" accept = tools.showDialog.yesno( tools.addonName + " - Custom Sources Install", line1, line2, line3, "Cancel", "Install") if accept == 0: return install_progress = tools.progressDialog install_progress.create(tools.addonName, 'Extracting - %s' % pack_name, 'Please Wait...') install_progress.update(-1) try: for folder in folders: for zip_file in file_list: if zip_file.startswith(folder): file.extract(zip_file, tools.dataPath) try: file.close() install_progress.close() except: pass tools.showDialog.ok(tools.addonName, 'Successfully Installed - %s' % pack_name) except: import traceback traceback.print_exc() install_progress.close() tools.showDialog.ok(tools.addonName, 'Failed to install - %s', 'Please check the log for further details') return customProviders.providers().update_known_providers()