From 752ca35da7704da97e1b33db0201994d67fae7e3 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Fri, 6 Feb 2026 23:46:12 +0100 Subject: [PATCH] refactor: remove download --- build.py | 5 ----- config/config.json.example | 2 +- src/build.py | 20 +++++++++----------- src/config.py | 21 ++++++++++++++------- src/download.py | 20 -------------------- test/test_html.py | 7 ++----- test/test_html_slides.py | 7 ++----- 7 files changed, 28 insertions(+), 54 deletions(-) delete mode 100644 src/download.py diff --git a/build.py b/build.py index 32c13fb..b913c57 100644 --- a/build.py +++ b/build.py @@ -1,12 +1,7 @@ import src.build as build import src.config as config -import src.download as download conf = config.Config() -dl = download.Download(conf) - -# Download the content files: -dl.download_git_content() # Build Everything: bd = build.Build(conf) diff --git a/config/config.json.example b/config/config.json.example index 3ae6cdc..47e4a53 100644 --- a/config/config.json.example +++ b/config/config.json.example @@ -1,3 +1,3 @@ { - "git_url" : "git@github.com:DARC-e-V/50ohm-contents-dl.git", + "content_path" : "/home/your_path_to/50ohm-content-dl" } diff --git a/src/build.py b/src/build.py index c431868..044be39 100644 --- a/src/build.py +++ b/src/build.py @@ -31,7 +31,7 @@ class Build: self.__build_chapter_slidedeck = memory.cache(self.__build_chapter_slidedeck) def __parse_katalog(self): - with self.config.p_fragenkatalog.open() as file: + with self.config.p_data_fragenkatalog.open() as file: fragenkatalog = json.load(file) questions = {} @@ -54,7 +54,7 @@ class Build: question_template = self.env.get_template(template_file) - with (self.config.p_data / "git_content/contents/questions/metadata3b.json").open() as file: + with (self.config.p_data_metadata).open() as file: metadata_json = json.load(file) question = None @@ -178,7 +178,7 @@ class Build: file.write(result) def __include_handler(self, include): - with (self.config.p_data / f"git_content/contents/html/{include}.html").open() as file: + with (self.config.p_data_html / f"{include}.html").open() as file: return file.read() # cached @@ -339,7 +339,7 @@ class Build: edition = edition.upper() - with (self.config.p_data / f"git_content/toc/{edition}.json").open() as file: + with (self.config.p_data_toc / f"{edition}.json").open() as file: book = json.load(file) chapters = book["chapters"] @@ -348,10 +348,10 @@ class Build: ident = section["ident"] section["content"] = None section["slide"] = None - with (self.config.p_data / f"git_content/contents/sections/{ident}.md").open() as sfile: + with (self.config.p_data_sections / f"{ident}.md").open() as sfile: section_content = sfile.read() section["content"] = section_content - with (self.config.p_data / f"git_content/contents/slides/{ident}.md").open() as sfile: + with (self.config.p_data_slides / f"{ident}.md").open() as sfile: section_content = sfile.read() section["slide"] = section_content @@ -386,10 +386,9 @@ class Build: ) def __parse_snippets(self): - snippets_dir = self.config.p_data / "git_content/contents/snippets/" snippets = {} - for md_file in Path(snippets_dir).glob("*.md"): + for md_file in Path(self.config.p_data_snippets).glob("*.md"): with md_file.open() as file: snippets[md_file.stem] = file.read() @@ -407,14 +406,13 @@ class Build: return snippets def __parse_contents(self): - static_dir = self.config.p_data / "git_content/contents/static/" static = [] - for static_file in Path(static_dir).glob("*.html"): + for static_file in Path(self.config.p_data_static).glob("*.html"): if "sidebar" not in static_file.stem: with static_file.open() as file: content = file.read() - sidebar_file = static_dir / f"{static_file.stem}_sidebar.html" + sidebar_file = self.config.p_data_static / f"{static_file.stem}_sidebar.html" if not sidebar_file.exists(): sidebar = "" else: diff --git a/src/config.py b/src/config.py index 21ad0b5..a87869c 100644 --- a/src/config.py +++ b/src/config.py @@ -13,15 +13,22 @@ class Config: else: self.config = {} - self.git_url = self.get_config_value("git_url", "git@github.com:DARC-e-V/50ohm-contents-dl.git") + self.p_data = Path(self.get_config_value("content_path", "/var/www/content")) - self.p_fragenkatalog = Path( - self.get_config_value("path_fragenkatalog", "./data/git_content/contents/questions/fragenkatalog3b.json") - ) + self.p_data_toc = self.p_data / "toc" - self.p_data = Path("./data") - self.p_data_photos = self.p_data / "git_content" / "contents" / "photos" - self.p_data_pictures = self.p_data / "git_content" / "contents" / "drawings" + self.p_data_contents = self.p_data / "contents" + self.p_data_questions = self.p_data_contents / "questions" + self.p_data_html = self.p_data_contents / "html" + self.p_data_photos = self.p_data_contents / "photos" + self.p_data_pictures = self.p_data_contents / "drawings" + self.p_data_sections = self.p_data_contents / "sections" + self.p_data_slides = self.p_data_contents / "slides" + self.p_data_snippets = self.p_data_contents / "snippets" + self.p_data_static = self.p_data_contents / "static" + + 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_photos = self.p_build / "photos" diff --git a/src/download.py b/src/download.py deleted file mode 100644 index db99f7c..0000000 --- a/src/download.py +++ /dev/null @@ -1,20 +0,0 @@ -from git import Repo - -from .config import Config - - -class Download: - def __init__(self, config: Config): - self.config = config - - def download_git_content(self): - repo_path = self.config.p_data / "git_content" - if not repo_path.exists(): - print("Cloning git repository, this may take a while ...") - Repo.clone_from(self.config.git_url, repo_path) - print("... done.") - else: - repo = Repo(repo_path) - origin = repo.remotes.origin - origin.pull() - print("Repository updated.") diff --git a/test/test_html.py b/test/test_html.py index a1296c4..e948c2f 100644 --- a/test/test_html.py +++ b/test/test_html.py @@ -5,16 +5,13 @@ from jinja2 import Environment, FileSystemLoader from mistletoe import Document import src.config as config -import src.download as download from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer conf = config.Config() -dl = download.Download(conf) -dl.download_git_content() def parse_katalog(): - with open("data/git_content/contents/questions/fragenkatalog3b.json") as fragenkatalog_file: + with open(conf.p_data_fragenkatalog) as fragenkatalog_file: fragenkatalog = json.load(fragenkatalog_file) questions = {} @@ -39,7 +36,7 @@ questions = parse_katalog() def question_stub(number): """Combines the original question dataset from BNetzA with our internal metadata""" - with open("data/git_content/contents/questions/metadata3b.json") as metadata_file: + with open(conf.p_data_metadata) as metadata_file: metadata = json.load(metadata_file) question = questions[number] metadata = metadata[f"{number}"] diff --git a/test/test_html_slides.py b/test/test_html_slides.py index 29b17ed..4b48234 100644 --- a/test/test_html_slides.py +++ b/test/test_html_slides.py @@ -6,16 +6,13 @@ from jinja2 import Environment, FileSystemLoader from mistletoe import Document import src.config as config -import src.download as download from renderer.fifty_ohm_html_slide_renderer import FiftyOhmHtmlSlideRenderer conf = config.Config() -dl = download.Download(conf) -dl.download_git_content() def parse_katalog(): - with open("data/git_content/contents/questions/fragenkatalog3b.json") as fragenkatalog_file: + with open(conf.p_data_fragenkatalog) as fragenkatalog_file: fragenkatalog = json.load(fragenkatalog_file) questions = {} @@ -51,7 +48,7 @@ def filter_shuffle_answers(seq): def question_stub(number): """Combines the original question dataset from BNetzA with our internal metadata""" - with open("data/git_content/contents/questions/metadata3b.json") as metadata_file: + with open(conf.p_data_metadata) as metadata_file: metadata = json.load(metadata_file) question = questions[number] metadata = metadata[f"{number}"]