diff --git a/scripts/blog.py b/scripts/blog.py index 85800e0..fc7ddad 100755 --- a/scripts/blog.py +++ b/scripts/blog.py @@ -479,6 +479,16 @@ def ctimer() -> float: return code_timer() if NCI else 0 +def update_media(config: dict[str, typing.Any]) -> int: + """update media.json""" + + with open("media/media.json", "w") as fp: + log("dumping media.json") + json.dump(MEDIA_INDEX, fp, indent=config["indent"]) + + return OK + + def log(msg: str, clr: str = LOG_CLR) -> int: if NCI: print( @@ -1730,8 +1740,6 @@ def blog(config: dict[str, typing.Any]) -> int: def media(config: dict[str, typing.Any]) -> int: """add media""" - assert config is config, "Unused" - if os.path.exists("licenses.json"): with open("licenses.json", "r") as fp: licenses: tuple[str, ...] = json.load(fp) @@ -1875,7 +1883,7 @@ def media(config: dict[str, typing.Any]) -> int: lnew(f"media {hash_hex} created") - return OK + return update_media(config) @cmds.new @@ -1897,14 +1905,12 @@ def lsmedia(config: dict[str, typing.Any]) -> int: def rmmedia(config: dict[str, typing.Any]) -> int: """remove media""" - assert config is config, "Unusued" - for mdx in select_medias(): imp(f"Removing media {mdx}") os.remove(f"media/{mdx}.{MEDIA_INDEX[mdx]['ext']}") del MEDIA_INDEX[mdx] - return OK + return update_media(config) @cmds.new @@ -1945,7 +1951,7 @@ def purgemedia(config: dict[str, typing.Any]) -> int: imp(f"Removing unindexed media {pid}") os.remove(f"media/{file}") - return OK + return update_media(config) @cmds.new @@ -2031,12 +2037,6 @@ def main() -> int: log(f"dumping config to {config.name!r}") json.dump(cfg, config, indent=cfg["indent"] if NCI else None) - # Update media.json - - with open("media/media.json", "w") as fp: - log("dumping media.json") - json.dump(MEDIA_INDEX, fp, indent=cfg["indent"]) - log(f"goodbye world, return {code}, total {ctimer() - main_t} s") return code