diff options
| author | TrainDoctor <traindoctor@protonmail.com> | 2022-08-08 13:06:04 -0700 |
|---|---|---|
| committer | TrainDoctor <traindoctor@protonmail.com> | 2022-08-08 13:06:04 -0700 |
| commit | c9e9c45b3738b13dce9417f06803b549426e6cbf (patch) | |
| tree | afeef2c00b56f13cce1522b8effe087cf3943fe9 | |
| parent | 6bc8a4fb1d5fb8bd3ec4bdf3c58c8486755701d9 (diff) | |
| download | decky-loader-c9e9c45b3738b13dce9417f06803b549426e6cbf.tar.gz decky-loader-c9e9c45b3738b13dce9417f06803b549426e6cbf.zip | |
Standardize logging in browser.py
| -rw-r--r-- | backend/browser.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/backend/browser.py b/backend/browser.py index 190f8bd5..bf89b430 100644 --- a/backend/browser.py +++ b/backend/browser.py @@ -18,6 +18,8 @@ from zipfile import ZipFile 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 @@ class PluginInstallContext: 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 @@ class PluginBrowser: 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 @@ class PluginBrowser: 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 @@ class PluginBrowser: 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 @@ class PluginBrowser: 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() |
