mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-07-12 02:32:00 +00:00
Standardize logging in browser.py
This commit is contained in:
+15
-14
@@ -18,6 +18,8 @@ from zipfile import ZipFile
|
|||||||
from helpers import get_ssl_context, get_user, get_user_group
|
from helpers import get_ssl_context, get_user, get_user_group
|
||||||
from injector import get_tab, inject_to_tab
|
from injector import get_tab, inject_to_tab
|
||||||
|
|
||||||
|
logger = getLogger("Browser")
|
||||||
|
|
||||||
class PluginInstallContext:
|
class PluginInstallContext:
|
||||||
def __init__(self, artifact, name, version, hash) -> None:
|
def __init__(self, artifact, name, version, hash) -> None:
|
||||||
self.artifact = artifact
|
self.artifact = artifact
|
||||||
@@ -27,7 +29,6 @@ class PluginInstallContext:
|
|||||||
|
|
||||||
class PluginBrowser:
|
class PluginBrowser:
|
||||||
def __init__(self, plugin_path, server_instance, plugins) -> None:
|
def __init__(self, plugin_path, server_instance, plugins) -> None:
|
||||||
self.log = getLogger("browser")
|
|
||||||
self.plugin_path = plugin_path
|
self.plugin_path = plugin_path
|
||||||
self.plugins = plugins
|
self.plugins = plugins
|
||||||
self.install_requests = {}
|
self.install_requests = {}
|
||||||
@@ -59,7 +60,7 @@ class PluginBrowser:
|
|||||||
if plugin['name'] == name:
|
if plugin['name'] == name:
|
||||||
return path.join(self.plugin_path, folder)
|
return path.join(self.plugin_path, folder)
|
||||||
except:
|
except:
|
||||||
self.log.debug(f"skipping {folder}")
|
logger.debug(f"skipping {folder}")
|
||||||
|
|
||||||
async def uninstall_plugin(self, name):
|
async def uninstall_plugin(self, name):
|
||||||
tab = await get_tab("SP")
|
tab = await get_tab("SP")
|
||||||
@@ -68,15 +69,15 @@ class PluginBrowser:
|
|||||||
if type(name) != str:
|
if type(name) != str:
|
||||||
data = await name.post()
|
data = await name.post()
|
||||||
name = data.get("name", "undefined")
|
name = data.get("name", "undefined")
|
||||||
self.log.info("uninstalling " + name)
|
logger.info("uninstalling " + name)
|
||||||
self.log.info(" at dir " + self.find_plugin_folder(name))
|
logger.info(" at dir " + self.find_plugin_folder(name))
|
||||||
await tab.evaluate_js(f"DeckyPluginLoader.unloadPlugin('{name}')")
|
await tab.evaluate_js(f"DeckyPluginLoader.unloadPlugin('{name}')")
|
||||||
if self.plugins[name]:
|
if self.plugins[name]:
|
||||||
self.plugins[name].stop()
|
self.plugins[name].stop()
|
||||||
self.plugins.pop(name, None)
|
self.plugins.pop(name, None)
|
||||||
rmtree(self.find_plugin_folder(name))
|
rmtree(self.find_plugin_folder(name))
|
||||||
except FileNotFoundError:
|
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")
|
return web.Response(text="Requested plugin uninstall")
|
||||||
|
|
||||||
@@ -84,18 +85,18 @@ class PluginBrowser:
|
|||||||
try:
|
try:
|
||||||
await self.uninstall_plugin(name)
|
await self.uninstall_plugin(name)
|
||||||
except:
|
except:
|
||||||
self.log.error(f"Plugin {name} not installed, skipping uninstallation")
|
logger.error(f"Plugin {name} not installed, skipping uninstallation")
|
||||||
self.log.info(f"Installing {name} (Version: {version})")
|
logger.info(f"Installing {name} (Version: {version})")
|
||||||
async with ClientSession() as client:
|
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())
|
res = await client.get(artifact, ssl=get_ssl_context())
|
||||||
if res.status == 200:
|
if res.status == 200:
|
||||||
self.log.debug("Got 200. Reading...")
|
logger.debug("Got 200. Reading...")
|
||||||
data = await res.read()
|
data = await res.read()
|
||||||
self.log.debug(f"Read {len(data)} bytes")
|
logger.debug(f"Read {len(data)} bytes")
|
||||||
res_zip = BytesIO(data)
|
res_zip = BytesIO(data)
|
||||||
with ProcessPoolExecutor() as executor:
|
with ProcessPoolExecutor() as executor:
|
||||||
self.log.debug("Unzipping...")
|
logger.debug("Unzipping...")
|
||||||
ret = await get_event_loop().run_in_executor(
|
ret = await get_event_loop().run_in_executor(
|
||||||
executor,
|
executor,
|
||||||
self._unzip_to_plugin_dir,
|
self._unzip_to_plugin_dir,
|
||||||
@@ -104,12 +105,12 @@ class PluginBrowser:
|
|||||||
hash
|
hash
|
||||||
)
|
)
|
||||||
if ret:
|
if ret:
|
||||||
self.log.info(f"Installed {name} (Version: {version})")
|
logger.info(f"Installed {name} (Version: {version})")
|
||||||
await inject_to_tab("SP", "window.syncDeckyPlugins()")
|
await inject_to_tab("SP", "window.syncDeckyPlugins()")
|
||||||
else:
|
else:
|
||||||
self.log.fatal(f"SHA-256 Mismatch!!!! {name} (Version: {version})")
|
logger.fatal(f"SHA-256 Mismatch!!!! {name} (Version: {version})")
|
||||||
else:
|
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):
|
async def install_plugin(self, request):
|
||||||
data = await request.post()
|
data = await request.post()
|
||||||
|
|||||||
Reference in New Issue
Block a user