diff --git a/backend/browser.py b/backend/browser.py index 190f8bd5d..bf89b4300 100644 --- a/backend/browser.py +++ b/backend/browser.py @@ -18,6 +18,8 @@ from helpers import get_ssl_context, get_user, get_user_group from injector import get_tab, inject_to_tab +logger = getLogger("Browser") + class PluginInstallContext: def __init__(self, artifact, name, version, hash) -> None: self.artifact = artifact @@ -27,7 +29,6 @@ def __init__(self, artifact, name, version, hash) -> None: class PluginBrowser: def __init__(self, plugin_path, server_instance, plugins) -> None: - self.log = getLogger("browser") self.plugin_path = plugin_path self.plugins = plugins self.install_requests = {} @@ -59,7 +60,7 @@ def find_plugin_folder(self, name): if plugin['name'] == name: return path.join(self.plugin_path, folder) except: - self.log.debug(f"skipping {folder}") + logger.debug(f"skipping {folder}") async def uninstall_plugin(self, name): tab = await get_tab("SP") @@ -68,15 +69,15 @@ async def uninstall_plugin(self, name): if type(name) != str: data = await name.post() name = data.get("name", "undefined") - self.log.info("uninstalling " + name) - self.log.info(" at dir " + self.find_plugin_folder(name)) + logger.info("uninstalling " + name) + logger.info(" at dir " + self.find_plugin_folder(name)) await tab.evaluate_js(f"DeckyPluginLoader.unloadPlugin('{name}')") if self.plugins[name]: self.plugins[name].stop() self.plugins.pop(name, None) rmtree(self.find_plugin_folder(name)) except FileNotFoundError: - self.log.warning(f"Plugin {name} not installed, skipping uninstallation") + logger.warning(f"Plugin {name} not installed, skipping uninstallation") return web.Response(text="Requested plugin uninstall") @@ -84,18 +85,18 @@ async def _install(self, artifact, name, version, hash): try: await self.uninstall_plugin(name) except: - self.log.error(f"Plugin {name} not installed, skipping uninstallation") - self.log.info(f"Installing {name} (Version: {version})") + logger.error(f"Plugin {name} not installed, skipping uninstallation") + logger.info(f"Installing {name} (Version: {version})") async with ClientSession() as client: - self.log.debug(f"Fetching {artifact}") + logger.debug(f"Fetching {artifact}") res = await client.get(artifact, ssl=get_ssl_context()) if res.status == 200: - self.log.debug("Got 200. Reading...") + logger.debug("Got 200. Reading...") data = await res.read() - self.log.debug(f"Read {len(data)} bytes") + logger.debug(f"Read {len(data)} bytes") res_zip = BytesIO(data) with ProcessPoolExecutor() as executor: - self.log.debug("Unzipping...") + logger.debug("Unzipping...") ret = await get_event_loop().run_in_executor( executor, self._unzip_to_plugin_dir, @@ -104,12 +105,12 @@ async def _install(self, artifact, name, version, hash): hash ) if ret: - self.log.info(f"Installed {name} (Version: {version})") + logger.info(f"Installed {name} (Version: {version})") await inject_to_tab("SP", "window.syncDeckyPlugins()") else: - self.log.fatal(f"SHA-256 Mismatch!!!! {name} (Version: {version})") + logger.fatal(f"SHA-256 Mismatch!!!! {name} (Version: {version})") else: - self.log.fatal(f"Could not fetch from URL. {await res.text()}") + logger.fatal(f"Could not fetch from URL. {await res.text()}") async def install_plugin(self, request): data = await request.post()