Skip to content

Commit

Permalink
Remove path and build_path fields from config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrench56 committed Jul 8, 2024
1 parent c4e46d6 commit f948564
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
18 changes: 5 additions & 13 deletions src/backend/api/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 0 additions & 2 deletions src/backend/config/config.toml
Original file line number Diff line number Diff line change
@@ -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!"

Expand Down
5 changes: 3 additions & 2 deletions src/backend/server/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

from pathlib import Path
from utils import config, perf, processes
from utils.const import BUILD_PATH, FRONTEND_PATH


def _start_frontend_build() -> subprocess.Popen:
conf = config.fetch().get('frontend')
return processes.add_subprocess(
subprocess.Popen(
conf.get('build').split(' '),
cwd=conf.get('path'),
cwd=FRONTEND_PATH,
stdout=(
None
if conf.get('show_output')
Expand All @@ -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())
)
Expand Down
8 changes: 5 additions & 3 deletions src/backend/utils/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions src/backend/utils/feature_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',),
Expand Down Expand Up @@ -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]:
Expand Down
4 changes: 3 additions & 1 deletion src/backend/utils/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))))
Expand Down

0 comments on commit f948564

Please sign in to comment.