def handleError(self, err): if config.debug: # Allow websocket errors to appear on /Debug import main main.DebugHook.handleError() else: ui_request = UiRequest(self.server, {}, self.environ, self.start_response) block_gen = ui_request.error500("UiWSGIHandler error: %s" % Debug.formatExceptionMessage(err)) for block in block_gen: self.write(block)
def pluginAction(self, action, address, inner_path): site = self.server.sites.get(address) plugin_manager = PluginManager.plugin_manager # Install/update path should exists if action in ("add", "update", "add_request"): if not site: raise Exception("Site not found") if not site.storage.isDir(inner_path): raise Exception("Directory not found on the site") try: plugin_info = site.storage.loadJson(inner_path + "/plugin_info.json") plugin_data = (plugin_info["rev"], plugin_info["description"], plugin_info["name"]) except Exception as err: raise Exception("Invalid plugin_info.json: %s" % Debug.formatExceptionMessage(err)) source_path = site.storage.getPath(inner_path) target_path = plugin_manager.path_installed_plugins + "/" + address + "/" + inner_path plugin_config = plugin_manager.config.setdefault(site.address, {}).setdefault( inner_path, {}) # Make sure plugin (not)installed if action in ("add", "add_request") and os.path.isdir(target_path): raise Exception("Plugin already installed") if action in ("update", "remove") and not os.path.isdir(target_path): raise Exception("Plugin not installed") # Do actions if action == "add": shutil.copytree(source_path, target_path) plugin_config["date_added"] = int(time.time()) plugin_config["rev"] = plugin_info["rev"] plugin_config["enabled"] = True if action == "update": shutil.rmtree(target_path) shutil.copytree(source_path, target_path) plugin_config["rev"] = plugin_info["rev"] plugin_config["date_updated"] = time.time() if action == "remove": del plugin_manager.config[address][inner_path] shutil.rmtree(target_path)