From a21931b8905a63e04293f51a303944172cb06111 Mon Sep 17 00:00:00 2001 From: Tim Grelka Date: Sat, 14 Feb 2026 20:37:42 +0100 Subject: [PATCH] feat: allow configuration of root paths via CLI --- main.py | 29 +++-------------------------- src/config.py | 7 ++++--- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/main.py b/main.py index a7b2830..534b4ae 100644 --- a/main.py +++ b/main.py @@ -2,10 +2,8 @@ from typing import Annotated import typer -import api.directus as directus import src.build as build import src.config as config -import src.download as download from src.edition import Edition app = typer.Typer() @@ -21,33 +19,12 @@ def main( Edition.ea, Edition.nea, ], - skip_download_editions: Annotated[ - bool, typer.Option(help="Skip download for editions, will use cached files or fail.") - ] = False, - skip_download_assets: Annotated[ - bool, typer.Option(help="Skip download for assets, will use cached assets or paceholders.") - ] = False, + source: Annotated[str | None, typer.Option(help="Content source directory.")] = None, + destination: Annotated[str | None, typer.Option(help="Destination directory to build to.")] = None, ) -> None: - conf = config.Config() - api = directus.DirectusAPI(conf.question_base_url, conf.question_access_token) - content_api = directus.DirectusAPI(conf.content_base_url, conf.content_access_token) - dl = download.Download(api, content_api, conf) + conf = config.Config(content_path=source, build_path=destination) bd = build.Build(conf) - if not skip_download_editions: - # Download the text files - for e in edition: - dl.download_edition(e) - - if not skip_download_assets: - # Download additional files - # dl.download_question_metadata() # (now constant file metadata3b.json) - dl.download_photos() - dl.download_pictures() - dl.download_includes() - dl.download_snippets() - dl.download_content() - # Build surrounding website bd.build_website() # Build individual editions diff --git a/src/config.py b/src/config.py index a87869c..2fdc66d 100644 --- a/src/config.py +++ b/src/config.py @@ -6,14 +6,14 @@ from pathlib import Path class Config: __env_prefix = "OHM" - def __init__(self): + def __init__(self, content_path: str = None, build_path: str = None): if os.path.isfile("config/config.json"): with open("config/config.json") as file: self.config = json.load(file) else: self.config = {} - self.p_data = Path(self.get_config_value("content_path", "/var/www/content")) + self.p_data = Path(self.get_config_value("content") if content_path is None else content_path) self.p_data_toc = self.p_data / "toc" @@ -30,12 +30,13 @@ class Config: self.p_data_fragenkatalog = self.p_data_questions / "fragenkatalog3b.json" self.p_data_metadata = self.p_data_questions / "metadata3b.json" - self.p_build = Path("./build") + self.p_build = Path(self.get_config_value("build_path", "./build") if build_path is None else build_path) self.p_build_photos = self.p_build / "photos" self.p_build_pictures = self.p_build / "pictures" self.p_build_assets = self.p_build / "assets" self.p_assets = Path("./assets") + self.p_templates = Path("./templates") def get_config_value(self, key: str, default=None): if key in self.config: