From 9de971d2ac3688aedfe93f1ed210e650933b0dd0 Mon Sep 17 00:00:00 2001 From: Flo Greistorfer Date: Wed, 14 Aug 2024 10:46:05 +0200 Subject: [PATCH] Fixed package detection --- .version | 2 +- builder.py | 18 +++++++++--------- modules/argumentparser.py | 10 ++++++---- modules/generate_html.py | 9 ++++++--- modules/svg_handling.py | 13 ++++++++----- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.version b/.version index 1506473..b539ade 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2.2.6 \ No newline at end of file +2.2.7 \ No newline at end of file diff --git a/builder.py b/builder.py index 67988ea..5f85ce8 100755 --- a/builder.py +++ b/builder.py @@ -17,11 +17,13 @@ from modules.generate_html import list_folder, EXCLUDES # fmt: off # Constants -if __package__ == None: - __package__ = "" -SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__).removesuffix(__package__)) -STATIC_FILES_DIR = os.path.join(os.path.abspath(SCRIPT_DIR), "files") -VERSION = open(os.path.join(SCRIPT_DIR, ".version"), "r", encoding="utf-8").read() +if __package__ is None: + PACKAGE = "" +else: + PACKAGE = __package__ +SCRIPTDIR = os.path.abspath(os.path.dirname(__file__).removesuffix(PACKAGE)) +STATIC_FILES_DIR = os.path.join(os.path.abspath(SCRIPTDIR), "files") +VERSION = open(os.path.join(SCRIPTDIR, ".version"), "r", encoding="utf-8").read() 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", @@ -94,7 +96,7 @@ def copy_static_files(_args: Args) -> None: if "url" in foldericon: shutil.copyfile(_args.theme_path, os.path.join(static_dir, "theme.css")) return - with open(os.path.join(SCRIPT_DIR, foldericon), "r", encoding="utf-8") as f: + with open(os.path.join(SCRIPTDIR, foldericon), "r", encoding="utf-8") as f: svg = f.read() if "svg.j2" in foldericon: colorscheme = extract_colorscheme(_args.theme_path) @@ -160,9 +162,7 @@ def get_total_folders(folder: str, _args: Args, _total: int = 0) -> int: items = sorted(os.listdir(folder)) for item in items: if item not in EXCLUDES and os.path.isdir(os.path.join(folder, item)) and not item.startswith("."): - if item not in _args.exclude_folders and not any( - fnmatch.fnmatchcase(os.path.join(folder, item), exclude) for exclude in _args.exclude_folders - ): + if item not in _args.exclude_folders and not any(fnmatch.fnmatchcase(os.path.join(folder, item), exclude) for exclude in _args.exclude_folders): _total = get_total_folders(os.path.join(folder, item), _args, _total) return _total diff --git a/modules/argumentparser.py b/modules/argumentparser.py index 0d2ea7b..31f460e 100644 --- a/modules/argumentparser.py +++ b/modules/argumentparser.py @@ -4,10 +4,12 @@ import os import argparse from rich_argparse import RichHelpFormatter, HelpPreviewAction - -if __package__ == None: - __package__ = "" -DEFAULT_THEME_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__).removesuffix(__package__)), "templates", "default.css") +if __package__ is None: + PACKAGE = "" +else: + PACKAGE = __package__ +SCRIPTDIR = os.path.abspath(os.path.dirname(__file__).removesuffix(PACKAGE)) +DEFAULT_THEME_PATH = os.path.join(SCRIPTDIR, "templates", "default.css") DEFAULT_AUTHOR = "Author" diff --git a/modules/generate_html.py b/modules/generate_html.py index df8cba5..5d365c0 100644 --- a/modules/generate_html.py +++ b/modules/generate_html.py @@ -13,8 +13,11 @@ import modules.cclicense as cclicense from modules.argumentparser import Args # Constants for file paths and exclusions -if __package__ == None: - __package__ = "" +if __package__ is None: + PACKAGE = "" +else: + PACKAGE = __package__ +SCRIPTDIR = os.path.abspath(os.path.dirname(__file__).removesuffix(PACKAGE)) FAVICON_PATH = ".static/favicon.ico" GLOBAL_CSS_PATH = ".static/global.css" EXCLUDES = ["index.html", "manifest.json", "robots.txt"] @@ -23,7 +26,7 @@ EXCLUDES = ["index.html", "manifest.json", "robots.txt"] Image.MAX_IMAGE_PIXELS = 933120000 # Initialize Jinja2 environment for template rendering -env = Environment(loader=FileSystemLoader(os.path.join(os.path.abspath(os.path.dirname(__file__).removesuffix(__package__)), "templates"))) +env = Environment(loader=FileSystemLoader(os.path.join(SCRIPTDIR, "templates"))) thumbnails: List[Tuple[str, str]] = [] info: Dict[str, str] = {} pbardict: Dict[str, tqdm] = {} diff --git a/modules/svg_handling.py b/modules/svg_handling.py index 74ea32a..4f8ac32 100644 --- a/modules/svg_handling.py +++ b/modules/svg_handling.py @@ -14,16 +14,19 @@ except ImportError: SVGSUPPORT = False from modules.argumentparser import Args -from modules.css_color import css_color_to_hex, extract_theme_color, extract_colorscheme +from modules.css_color import extract_theme_color, extract_colorscheme # Define constants for static files directory and icon sizes -if __package__ == None: - __package__ = "" -STATIC_FILES_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__).removesuffix(__package__)), "files") +if __package__ is None: + PACKAGE = "" +else: + PACKAGE = __package__ +SCRIPTDIR = os.path.abspath(os.path.dirname(__file__).removesuffix(PACKAGE)) +STATIC_FILES_DIR = os.path.join(SCRIPTDIR, "files") ICON_SIZES = ["36x36", "48x48", "72x72", "96x96", "144x144", "192x192", "512x512"] # Initialize Jinja2 environment for template rendering -env = Environment(loader=FileSystemLoader(os.path.join(os.path.abspath(os.path.dirname(__file__).removesuffix(__package__)), "templates"))) +env = Environment(loader=FileSystemLoader(os.path.join(SCRIPTDIR, "templates"))) class Icon: