From f94856467b5dae43ce408078121687362fdc0c5e Mon Sep 17 00:00:00 2001 From: Wrench56 Date: Mon, 8 Jul 2024 18:45:47 -0400 Subject: [PATCH] Remove `path` and `build_path` fields from `config.toml` --- src/backend/api/serve.py | 18 +++++------------- src/backend/config/config.toml | 2 -- src/backend/server/build.py | 5 +++-- src/backend/utils/const.py | 8 +++++--- src/backend/utils/feature_build.py | 4 ++-- src/backend/utils/status.py | 4 +++- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/backend/api/serve.py b/src/backend/api/serve.py index 5110c0f..d988022 100644 --- a/src/backend/api/serve.py +++ b/src/backend/api/serve.py @@ -2,26 +2,18 @@ import logging import os -from utils import config, stack - -_BUILD_PATH = None +from utils import stack +from utils.const import BUILD_PATH async def page(path: str) -> FileResponse: - _cache_buildpath() mname = stack.get_caller(depth=2)[0] if not mname.startswith('plugins.plugins.'): logging.error(f'Non-plugin called serve.page() API: "{mname}"') - return FileResponse(f'{_BUILD_PATH}/plugins') + return FileResponse(f'{BUILD_PATH}/plugins') pname = mname.split('.')[2] - fpath = f'{_BUILD_PATH}/plugins/{pname}/{path}.html' + fpath = f'{BUILD_PATH}/plugins/{pname}/{path}.html' if not os.path.exists(fpath): logging.error(f'Plugin page "{path}" for plugin "{pname}" does not exist') - return FileResponse(f'{_BUILD_PATH}/dne.html') + return FileResponse(f'{BUILD_PATH}/dne.html') return FileResponse(fpath) - - -def _cache_buildpath() -> None: - global _BUILD_PATH - if _BUILD_PATH is None: - _BUILD_PATH = config.fetch().get("frontend").get("build_path") diff --git a/src/backend/config/config.toml b/src/backend/config/config.toml index 5d9674c..9b9b865 100644 --- a/src/backend/config/config.toml +++ b/src/backend/config/config.toml @@ -1,7 +1,5 @@ [frontend] -path = "../frontend" build = "npm run build" -build_path = "../public" show_output = true motd = "Memory: {{teal}}{{memory_used}} MB{{end}} / {{memory_total}} MB\nCPU: {{teal}}{{cpu_percent}}%{{end}}\nUsers: {{teal}}{{active_users}}{{end}}\nHave a great day!" diff --git a/src/backend/server/build.py b/src/backend/server/build.py index d065761..b534f9c 100644 --- a/src/backend/server/build.py +++ b/src/backend/server/build.py @@ -5,6 +5,7 @@ from pathlib import Path from utils import config, perf, processes +from utils.const import BUILD_PATH, FRONTEND_PATH def _start_frontend_build() -> subprocess.Popen: @@ -12,7 +13,7 @@ def _start_frontend_build() -> subprocess.Popen: return processes.add_subprocess( subprocess.Popen( conf.get('build').split(' '), - cwd=conf.get('path'), + cwd=FRONTEND_PATH, stdout=( None if conf.get('show_output') @@ -38,7 +39,7 @@ def build_frontend() -> int: def get_frontend_size() -> Tuple[float, str]: - root_directory = Path(config.fetch().get('frontend').get('build_path')) + root_directory = Path(BUILD_PATH) return _format_units( sum(f.stat().st_size for f in root_directory.glob('**/*') if f.is_file()) ) diff --git a/src/backend/utils/const.py b/src/backend/utils/const.py index 89335da..c38e7a7 100644 --- a/src/backend/utils/const.py +++ b/src/backend/utils/const.py @@ -4,6 +4,8 @@ PLUGINS_DIR: str = f'{_plugins}/plugins' PLUGINS_DOWNLOAD: str = f'{_plugins}/downloads' -_frontend: str = '../frontend' -FRONTEND_PLUGINS_DIR = f'{_frontend}/src/lib/plugins' -FRONTEND_PAGES_DIR = f'{_frontend}/src/routes/plugins' +FRONTEND_PATH: str = '../frontend' +FRONTEND_PLUGINS_DIR = f'{FRONTEND_PATH}/src/lib/plugins' +FRONTEND_PAGES_DIR = f'{FRONTEND_PATH}/src/routes/plugins' + +BUILD_PATH = '../public' diff --git a/src/backend/utils/feature_build.py b/src/backend/utils/feature_build.py index 9ded1e7..855c30c 100644 --- a/src/backend/utils/feature_build.py +++ b/src/backend/utils/feature_build.py @@ -3,6 +3,7 @@ import logging from utils import config +from utils.const import FRONTEND_PATH _FILE_OF_FEATURE: Dict[str, Tuple] = { 'STATUS_IN_SETTINGS': ('src/routes/settings/+page.svelte', 'src/lib/components/settings/Box.svelte',), @@ -69,8 +70,7 @@ def _decode_feature_files(feature: str) -> Optional[List[str]]: if not filenames: logging.error(f'Non-existing feature: "{feature}"') return None - path = config.fetch().get('frontend').get('path') - return [f'{path}/{filename}' for filename in filenames] + return [f'{FRONTEND_PATH}/{filename}' for filename in filenames] def _find_html_features(feature: str, lines: list) -> List[int]: diff --git a/src/backend/utils/status.py b/src/backend/utils/status.py index 755bae4..a6a80e8 100644 --- a/src/backend/utils/status.py +++ b/src/backend/utils/status.py @@ -3,16 +3,18 @@ from typing import Dict, List, Optional from utils import config, processes +from utils.const import FRONTEND_PATH _status: Dict[str, str] = {} _login_disabled: List[str] = [] + def get() -> Dict[str, str]: return _status.copy() def update() -> None: - cwd = config.fetch().get('frontend').get('path') + cwd = FRONTEND_PATH stdout = None if config.fetch().get('status').get('show_output') else subprocess.DEVNULL disabled = tuple(map(str.strip, config.fetch().get('status').get('disable_statuses'))) _login_disabled.extend(tuple(map(str.strip, config.fetch().get('login').get('disable_statuses'))))