From 77a3a558b5b3e386dec2dc520f32934234fcfa3e Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 21 Jan 2025 22:58:00 -0800 Subject: [PATCH] Publish? --- tools/build/publish.py | 46 +++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/tools/build/publish.py b/tools/build/publish.py index 7d8adcf..954b1b2 100644 --- a/tools/build/publish.py +++ b/tools/build/publish.py @@ -18,21 +18,26 @@ SRC_DIR: Path = ROOT / "output" def log(msg): print(f"[PUBLISH.PY] {msg}") + +log(f"Version is {VERSION}") +log(f"Package is is {PACKAGE}") log(f"Running in {ROOT}") if not ROOT.is_dir(): log("Root is not a directory, cannot continue") exit(1) -log(f"Output dir is {SRC_DIR}") +log(f"Source dir is {SRC_DIR}") if not SRC_DIR.exists(): - log("Output dir doesn't exist, cannot continue") + log("Source dir doesn't exist, cannot continue") exit(1) -IndexEntry = TypedDict( - "IndexEntry", - {"title": str, "group": str, "handout_file": str, "solutions_file": str | None}, -) - +def upload(data, target: string): + requests.put( + f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}", + auth=AUTH, + data=data + ) + return f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}" index = SRC_DIR / "index.json" with index.open("r") as f: @@ -48,24 +53,16 @@ for handout in index: h_url = None s_url = None - target = f"{group} - {title}.pdf" - requests.put( - f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}", - auth=AUTH, - data=h_file.open('rb').read() + h_url = upload( + h_file.open('rb').read(), + f"{group} - {title}.pdf" ) - h_url = f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}" - if s_file is not None: - target = f"{group} - {title}.sols.pdf" - requests.put( - f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/{target}", - auth=AUTH, - data=s_file.open('rb').read() + s_url = upload( + s_file.open('rb').read(), + f"{group} - {title}.sols.pdf" ) - s_url = f"{URL}/api/packages/{USER}/generic/ormc-handouts/{VERSION}/{target}" - log(f"Published {title}") @@ -76,8 +73,7 @@ for handout in index: "solutions": s_url }) -requests.put( - f"{URL}/api/packages/{USER}/generic/{PACKAGE}/{VERSION}/index.json", - auth=AUTH, - data=json.dumps(new_index) +upload( + json.dumps(new_index), + "index.json" ) \ No newline at end of file