refactor: remove download

This commit is contained in:
Matthias Jung
2026-02-06 23:46:12 +01:00
parent 8f7e88132e
commit 752ca35da7
7 changed files with 28 additions and 54 deletions
-5
View File
@@ -1,12 +1,7 @@
import src.build as build import src.build as build
import src.config as config import src.config as config
import src.download as download
conf = config.Config() conf = config.Config()
dl = download.Download(conf)
# Download the content files:
dl.download_git_content()
# Build Everything: # Build Everything:
bd = build.Build(conf) bd = build.Build(conf)
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
"git_url" : "[email protected]:DARC-e-V/50ohm-contents-dl.git", "content_path" : "/home/your_path_to/50ohm-content-dl"
} }
+9 -11
View File
@@ -31,7 +31,7 @@ class Build:
self.__build_chapter_slidedeck = memory.cache(self.__build_chapter_slidedeck) self.__build_chapter_slidedeck = memory.cache(self.__build_chapter_slidedeck)
def __parse_katalog(self): 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) fragenkatalog = json.load(file)
questions = {} questions = {}
@@ -54,7 +54,7 @@ class Build:
question_template = self.env.get_template(template_file) 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) metadata_json = json.load(file)
question = None question = None
@@ -178,7 +178,7 @@ class Build:
file.write(result) file.write(result)
def __include_handler(self, include): 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() return file.read()
# cached # cached
@@ -339,7 +339,7 @@ class Build:
edition = edition.upper() 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) book = json.load(file)
chapters = book["chapters"] chapters = book["chapters"]
@@ -348,10 +348,10 @@ class Build:
ident = section["ident"] ident = section["ident"]
section["content"] = None section["content"] = None
section["slide"] = 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 = sfile.read()
section["content"] = section_content 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_content = sfile.read()
section["slide"] = section_content section["slide"] = section_content
@@ -386,10 +386,9 @@ class Build:
) )
def __parse_snippets(self): def __parse_snippets(self):
snippets_dir = self.config.p_data / "git_content/contents/snippets/"
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: with md_file.open() as file:
snippets[md_file.stem] = file.read() snippets[md_file.stem] = file.read()
@@ -407,14 +406,13 @@ class Build:
return snippets return snippets
def __parse_contents(self): def __parse_contents(self):
static_dir = self.config.p_data / "git_content/contents/static/"
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: if "sidebar" not in static_file.stem:
with static_file.open() as file: with static_file.open() as file:
content = file.read() 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(): if not sidebar_file.exists():
sidebar = "" sidebar = ""
else: else:
+14 -7
View File
@@ -13,15 +13,22 @@ class Config:
else: else:
self.config = {} self.config = {}
self.git_url = self.get_config_value("git_url", "[email protected]: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.p_data_toc = self.p_data / "toc"
self.get_config_value("path_fragenkatalog", "./data/git_content/contents/questions/fragenkatalog3b.json")
)
self.p_data = Path("./data") self.p_data_contents = self.p_data / "contents"
self.p_data_photos = self.p_data / "git_content" / "contents" / "photos" self.p_data_questions = self.p_data_contents / "questions"
self.p_data_pictures = self.p_data / "git_content" / "contents" / "drawings" 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 = Path("./build")
self.p_build_photos = self.p_build / "photos" self.p_build_photos = self.p_build / "photos"
-20
View File
@@ -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.")
+2 -5
View File
@@ -5,16 +5,13 @@ from jinja2 import Environment, FileSystemLoader
from mistletoe import Document from mistletoe import Document
import src.config as config import src.config as config
import src.download as download
from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer from renderer.fifty_ohm_html_renderer import FiftyOhmHtmlRenderer
conf = config.Config() conf = config.Config()
dl = download.Download(conf)
dl.download_git_content()
def parse_katalog(): 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) fragenkatalog = json.load(fragenkatalog_file)
questions = {} questions = {}
@@ -39,7 +36,7 @@ questions = parse_katalog()
def question_stub(number): def question_stub(number):
"""Combines the original question dataset from BNetzA with our internal metadata""" """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) metadata = json.load(metadata_file)
question = questions[number] question = questions[number]
metadata = metadata[f"{number}"] metadata = metadata[f"{number}"]
+2 -5
View File
@@ -6,16 +6,13 @@ from jinja2 import Environment, FileSystemLoader
from mistletoe import Document from mistletoe import Document
import src.config as config import src.config as config
import src.download as download
from renderer.fifty_ohm_html_slide_renderer import FiftyOhmHtmlSlideRenderer from renderer.fifty_ohm_html_slide_renderer import FiftyOhmHtmlSlideRenderer
conf = config.Config() conf = config.Config()
dl = download.Download(conf)
dl.download_git_content()
def parse_katalog(): 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) fragenkatalog = json.load(fragenkatalog_file)
questions = {} questions = {}
@@ -51,7 +48,7 @@ def filter_shuffle_answers(seq):
def question_stub(number): def question_stub(number):
"""Combines the original question dataset from BNetzA with our internal metadata""" """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) metadata = json.load(metadata_file)
question = questions[number] question = questions[number]
metadata = metadata[f"{number}"] metadata = metadata[f"{number}"]