def uninstall_package(self): import shutil packages = [i['pack_name'] for i in self.known_packages] if len(packages) == 0: tools.showDialog.ok(tools.addonName, tools.lang(32074).encode('utf-8')) return selection = tools.showDialog.select( "%s: %s Providers" % (tools.addonName, tools.lang(32075).encode('utf-8')), packages) if selection == -1: return package_name = packages[selection] confirm = tools.showDialog.yesno( tools.addonName, tools.lang(32076).encode('utf-8') + " %s" % package_name) if confirm == 0: return provider_path = os.path.join(self.providers_path, package_name) modules_path = os.path.join(self.modules_path, package_name) meta_path = os.path.join(self.meta_path, '%s.json' % package_name) if os.path.exists(provider_path): shutil.rmtree(provider_path) if os.path.exists(modules_path): shutil.rmtree(modules_path) if os.path.exists(meta_path): os.remove(meta_path) database.remove_package_providers(package_name) database.remove_provider_package(package_name) tools.showDialog.ok( tools.addonName, '%s ' % package_name + tools.lang(32077).encode('utf-8'))
def uninstall_package(self, package=None, silent=False): import shutil packages = [i['pack_name'] for i in self.known_packages] if package is None: if len(packages) == 0: tools.showDialog.ok(tools.addonName, tools.lang(32074)) return selection = tools.showDialog.select( "%s: %s %s" % (tools.addonName, tools.lang(32075), tools.lang(40068)), packages) if selection == -1: return package_name = packages[selection] confirm = tools.showDialog.yesno( tools.addonName, tools.lang(32076) + " %s" % package_name) if confirm == 0: return else: package_name = package try: provider_path = os.path.join(self.providers_path, package_name) modules_path = os.path.join(self.modules_path, package_name) meta_path = os.path.join(self.meta_path, '%s.json' % package_name) if os.path.exists(provider_path): shutil.rmtree(provider_path) if os.path.exists(modules_path): shutil.rmtree(modules_path) if os.path.exists(meta_path): os.remove(meta_path) database.remove_package_providers(package_name) database.remove_provider_package(package_name) import time time.sleep(2) if not silent: tools.showDialog.ok(tools.addonName, '%s ' % package_name + tools.lang(32077)) except: tools.showDialog.ok( tools.addonName, tools.language(40118).enocde('utf-8') % (tools.addonName, package_name))
def install_zip(self, zip_file, silent=False): file_list = zip_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 = zip_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: if not silent: self.failed_prompt() tools.log( 'Source pack is malformed, please check and correct issue in the meta file' ) return author = meta['author'] version = meta['version'] pack_name = meta['name'] remote_meta = meta.get('remote_meta', '') else: if not silent: self.failed_prompt() tools.log( 'Source pack is malformed, please check and correct issue in the meta file' ) import traceback traceback.print_exc() raise Exception if remote_meta == '': tools.showDialog.ok(tools.addonName, tools.lang(33016).encode('utf-8')) line1 = tools.colorString(tools.lang(33001).encode( 'utf-8')) + " %s - v%s" % (pack_name, version) line2 = tools.colorString( tools.lang(33002).encode('utf-8')) + "%s" % author line3 = tools.lang(33003).encode('utf-8') if not silent: accept = tools.showDialog.yesno( tools.addonName + " - %s" % tools.lang(33004).encode('utf-8'), line1, line2, line3, tools.lang(33005).encode('utf-8'), tools.lang(33006).encode('utf-8')) if accept == 0: return self.pre_update_collection = [ i for i in database.get_providers() if i['package'] == pack_name ] database.remove_package_providers(pack_name) folders = ['providerModules/', 'providers/'] meta_output_location = os.path.join(tools.dataPath, 'providerMeta', '%s.json' % pack_name) if os.path.isfile(meta_output_location): try: os.rename(meta_output_location, '%s.temp' % meta_output_location) except Exception as e: self.failure_cleanup(meta_output_location, pack_name, folders) tools.log('Failed to create temporary meta file') if not silent: tools.showDialog.ok(tools.addonName, tools.lang(33007).encode('utf-8')) return try: self.output_meta(meta) except: self.failure_cleanup(meta_output_location, pack_name, folders) tools.log('Failed to create new meta file') if not silent: self.failed_prompt() return else: self.output_meta(meta) if not silent: install_progress = tools.progressDialog install_progress.create( tools.addonName, '%s - %s' % (pack_name, tools.lang(33008).encode('utf-8')), tools.lang(33009).encode('utf-8')) install_progress.update(-1) try: for folder in folders: try: folder_path = os.path.join(tools.dataPath, folder.strip('/'), pack_name) if os.path.exists(folder_path): os.rename(folder_path, '%s.temp' % folder_path) for file in file_list: if file.startswith(folder): zip_file.extract(file, tools.dataPath) except: tools.log('Failed to extract to folder - %s' % folder) import traceback traceback.print_exc() self.failure_cleanup(meta_output_location, pack_name, folders) if not silent: self.failed_prompt() return try: zip_file.close() except: pass if not silent: install_progress.close() if not silent: tools.showDialog.ok( tools.addonName, '%s - %s' % (tools.lang(33010).encode('utf-8'), pack_name)) except: import traceback traceback.print_exc() if not silent: install_progress.close() tools.showDialog.ok( tools.addonName, '%s - %s' % (tools.lang(33012).encode('utf-8'), pack_name), tools.lang(33011).encode('utf-8')) return if os.path.exists('%s.temp' % meta_output_location): os.remove('%s.temp' % meta_output_location) for folder in folders: folder_path = os.path.join(tools.dataPath, folder.strip('/'), pack_name) if os.path.exists('%s.temp' % folder_path): shutil.rmtree('%s.temp' % folder_path) tools.log('Refreshing provider database ') database.add_provider_package(pack_name, author, remote_meta, version) self.update_known_providers() return True