addional check bruh

This commit is contained in:
2024-07-10 22:15:37 +02:00
parent 4402c31c48
commit 44f0cc39c6
2 changed files with 8 additions and 7 deletions

View File

@@ -77,7 +77,7 @@ def copy_static_files(_args: Args) -> None:
shutil.copyfile(_args.theme_path, os.path.join(static_dir, "theme.css")) shutil.copyfile(_args.theme_path, os.path.join(static_dir, "theme.css"))
def generate_thumbnail(arguments: Tuple[str, str, str, bool]) -> None: def generate_thumbnail(arguments: Tuple[str, str, str]) -> None:
""" """
Generate a thumbnail for a given image. Generate a thumbnail for a given image.
@@ -86,7 +86,7 @@ def generate_thumbnail(arguments: Tuple[str, str, str, bool]) -> None:
arguments : Tuple[str, str, str, bool] arguments : Tuple[str, str, str, bool]
A tuple containing the folder, item, root directory, and regenerate thumbnails flag. A tuple containing the folder, item, root directory, and regenerate thumbnails flag.
""" """
folder, item, root_directory, regenerate_thumbnails = arguments folder, item, root_directory = arguments
path = os.path.join(root_directory, ".thumbnails", folder.removeprefix(root_directory), item) + ".jpg" path = os.path.join(root_directory, ".thumbnails", folder.removeprefix(root_directory), item) + ".jpg"
oldpath = os.path.join(root_directory, ".thumbnails", folder.removeprefix(root_directory), os.path.splitext(item)[0]) + ".jpg" oldpath = os.path.join(root_directory, ".thumbnails", folder.removeprefix(root_directory), os.path.splitext(item)[0]) + ".jpg"
if os.path.exists(oldpath): if os.path.exists(oldpath):
@@ -94,9 +94,7 @@ def generate_thumbnail(arguments: Tuple[str, str, str, bool]) -> None:
shutil.move(oldpath, path) shutil.move(oldpath, path)
except FileNotFoundError: except FileNotFoundError:
pass pass
if not os.path.exists(path) or regenerate_thumbnails: if not os.path.exists(path):
if os.path.exists(path):
os.remove(path)
try: try:
with Image.open(os.path.join(folder, item)) as imgfile: with Image.open(os.path.join(folder, item)) as imgfile:
imgrgb = imgfile.convert("RGB") imgrgb = imgfile.convert("RGB")

View File

@@ -113,8 +113,11 @@ def process_image(item: str, folder: str, _args: Args, baseurl: str, sizelist: D
"width": sizelist[item]["width"], "width": sizelist[item]["width"],
"height": sizelist[item]["height"], "height": sizelist[item]["height"],
} }
if not os.path.exists(os.path.join(_args.root_directory, ".thumbnails", baseurl, item)): path = os.path.join(_args.root_directory, ".thumbnails", baseurl, item + ".jpg")
thumbnails.append((folder, item, _args.root_directory, _args.regenerate_thumbnails)) if not os.path.exists(path) or _args.regenerate_thumbnails:
if os.path.exists(path):
os.remove(path)
thumbnails.append((folder, item, _args.root_directory))
for _raw in raw: for _raw in raw:
if os.path.exists(os.path.join(folder, extsplit[0] + _raw)): if os.path.exists(os.path.join(folder, extsplit[0] + _raw)):