From bde5229d9dfc1f3c1ce146f20c278e8afe3b25d2 Mon Sep 17 00:00:00 2001 From: Flo Greistorfer Date: Mon, 8 Jul 2024 17:24:16 +0200 Subject: [PATCH] added sizelist cache --- StaticGalleryBuilder.code-workspace | 29 ++++++++++++++++++++++++++++- builder.py | 13 ++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/StaticGalleryBuilder.code-workspace b/StaticGalleryBuilder.code-workspace index 133b683..6f8144a 100644 --- a/StaticGalleryBuilder.code-workspace +++ b/StaticGalleryBuilder.code-workspace @@ -63,7 +63,7 @@ "version": "0.2.0", "configurations": [ { - "name": "Python Debugger: Current File", + "name": "Testfolder", "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/builder.py", @@ -81,6 +81,26 @@ "-n" ], "postDebugTask": "Delete Lockfile" + }, + { + "name": "woek", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/builder.py", + "console": "integratedTerminal", + "args": [ + "-p", + "/home/user/woek/Pictures", + "-w", + "file:///home/user/woek/Pictures", + "-t", + "Pictures", + "--theme", + "themes/kjoe.css", + "--use-fancy-folders", + "-n" + ], + "postDebugTask": "Delete Lockfile 2" } ] }, @@ -93,6 +113,13 @@ "type": "shell", "problemMatcher": [], "isBackground": true + }, + { + "label": "Delete Lockfile 2", + "command": "rm -f /home/user/woek/Pictures/.lock", + "type": "shell", + "problemMatcher": [], + "isBackground": true } ] } diff --git a/builder.py b/builder.py index 0ae63cc..ce7891a 100755 --- a/builder.py +++ b/builder.py @@ -26,7 +26,7 @@ DEFAULT_AUTHOR = "Author" VERSION = "1.8.0" RAW_EXTENSIONS = [".3fr", ".ari", ".arw", ".bay", ".braw", ".crw", ".cr2", ".cr3", ".cap", ".data", ".dcs", ".dcr", ".dng", ".drf", ".eip", ".erf", ".fff", ".gpr", ".iiq", ".k25", ".kdc", ".mdc", ".mef", ".mos", ".mrw", ".nef", ".nrw", ".obm", ".orf", ".pef", ".ptx", ".pxn", ".r3d", ".raf", ".raw", ".rwl", ".rw2", ".rwz", ".sr2", ".srf", ".srw", ".tif", ".tiff", ".x3f"] IMG_EXTENSIONS = [".jpg", ".jpeg"] -EXCLUDES = [".lock", "index.html", ".thumbnails", ".static"] +EXCLUDES = [".lock", "index.html", "sizelist.json", ".thumbnails", ".static"] NOT_LIST = ["*/Galleries/*", "Archives"] # fmt: on @@ -141,8 +141,11 @@ def get_total_folders(folder: str, _total: int = 0) -> int: def list_folder(folder: str, title: str) -> None: sizelist: Dict[Dict[str, int], Dict[str, int]] = {} - with open(os.path.join(folder, "sizelist.json"), "w+", encoding="utf-8") as sizelistfile: - sizelist = json.loads(sizelistfile.read()) + with open(os.path.join(folder, "sizelist.json"), "r+", encoding="utf-8") as sizelistfile: + try: + sizelist = json.loads(sizelistfile.read()) + except json.decoder.JSONDecodeError: + sizelist = {} items = os.listdir(folder) items.sort() images: List[Dict[str, Any]] = [] @@ -172,11 +175,9 @@ def list_folder(folder: str, title: str) -> None: contains_files = True if extsplit[1].lower() in args.file_extensions: if not sizelist.get(item): - print("fuck") with Image.open(os.path.join(folder, item)) as img: width, height = img.size sizelist[item] = {"width": width, "height": height} - print(sizelist) image = { "url": f"{args.web_root_url}{baseurl}{urllib.parse.quote(item)}", @@ -202,7 +203,9 @@ def list_folder(folder: str, title: str) -> None: if not args.non_interactive_mode: imgpbar.update(1) pbar.update(0) + sizelistfile.seek(0) sizelistfile.write(json.dumps(sizelist, indent=4)) + sizelistfile.truncate() if not contains_files and not args.use_fancy_folders: return if images or (args.use_fancy_folders and not contains_files) or (args.use_fancy_folders and args.ignore_other_files):