mirror of
https://github.com/greflm13/StaticGalleryBuilder.git
synced 2026-02-05 02:59:27 +00:00
added class constructor and regenerate now deletes .previews
This commit is contained in:
@@ -160,7 +160,9 @@ def get_total_folders(folder: str, _args: Args, _total: int = 0) -> int:
|
|||||||
items = sorted(os.listdir(folder))
|
items = sorted(os.listdir(folder))
|
||||||
for item in items:
|
for item in items:
|
||||||
if item not in EXCLUDES and os.path.isdir(os.path.join(folder, item)):
|
if item not in EXCLUDES and os.path.isdir(os.path.join(folder, item)):
|
||||||
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)
|
_total = get_total_folders(os.path.join(folder, item), _args, _total)
|
||||||
return _total
|
return _total
|
||||||
|
|
||||||
@@ -181,6 +183,9 @@ def main() -> None:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
Path(lock_file).touch()
|
Path(lock_file).touch()
|
||||||
|
if args.regenerate_thumbnails:
|
||||||
|
if os.path.exists(os.path.join(args.root_directory, ".thumbnails")):
|
||||||
|
shutil.rmtree(os.path.join(args.root_directory, ".thumbnails"))
|
||||||
os.makedirs(os.path.join(args.root_directory, ".thumbnails"), exist_ok=True)
|
os.makedirs(os.path.join(args.root_directory, ".thumbnails"), exist_ok=True)
|
||||||
|
|
||||||
copy_static_files(args)
|
copy_static_files(args)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
@@ -10,6 +11,7 @@ DEFAULT_THEME_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__).remo
|
|||||||
DEFAULT_AUTHOR = "Author"
|
DEFAULT_AUTHOR = "Author"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(init=True)
|
||||||
class Args:
|
class Args:
|
||||||
"""
|
"""
|
||||||
A class to store command-line arguments for the script.
|
A class to store command-line arguments for the script.
|
||||||
@@ -58,6 +60,24 @@ class Args:
|
|||||||
use_fancy_folders: bool
|
use_fancy_folders: bool
|
||||||
web_root_url: str
|
web_root_url: str
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
result: dict = {}
|
||||||
|
result["author_name"] = self.author_name
|
||||||
|
result["exclude_folders"] = self.exclude_folders
|
||||||
|
result["file_extensions"] = self.file_extensions
|
||||||
|
result["generate_webmanifest"] = self.generate_webmanifest
|
||||||
|
result["ignore_other_files"] = self.ignore_other_files
|
||||||
|
if self.license_type is not None:
|
||||||
|
result["license_type"] = self.license_type
|
||||||
|
result["non_interactive_mode"] = self.non_interactive_mode
|
||||||
|
result["regenerate_thumbnails"] = self.regenerate_thumbnails
|
||||||
|
result["root_directory"] = self.root_directory
|
||||||
|
result["site_title"] = self.site_title
|
||||||
|
result["theme_path"] = self.theme_path
|
||||||
|
result["use_fancy_folders"] = self.use_fancy_folders
|
||||||
|
result["web_root_url"] = self.web_root_url
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments(version: str) -> Args:
|
def parse_arguments(version: str) -> Args:
|
||||||
"""
|
"""
|
||||||
@@ -73,6 +93,7 @@ def parse_arguments(version: str) -> Args:
|
|||||||
Args
|
Args
|
||||||
An instance of the Args class containing the parsed arguments.
|
An instance of the Args class containing the parsed arguments.
|
||||||
"""
|
"""
|
||||||
|
# fmt: off
|
||||||
parser = argparse.ArgumentParser(description="Generate HTML files for a static image hosting website.", formatter_class=RichHelpFormatter)
|
parser = argparse.ArgumentParser(description="Generate HTML files for a static image hosting website.", formatter_class=RichHelpFormatter)
|
||||||
parser.add_argument("--exclude-folder", help="Folders to exclude from processing, globs supported (can be specified multiple times).", action="append", dest="exclude_folders", metavar="FOLDER")
|
parser.add_argument("--exclude-folder", help="Folders to exclude from processing, globs supported (can be specified multiple times).", action="append", dest="exclude_folders", metavar="FOLDER")
|
||||||
parser.add_argument("--generate-help-preview", action=HelpPreviewAction, path="help.svg")
|
parser.add_argument("--generate-help-preview", action=HelpPreviewAction, path="help.svg")
|
||||||
@@ -90,18 +111,20 @@ def parse_arguments(version: str) -> Args:
|
|||||||
parser.add_argument("-t", "--site-title", help="Title of the image hosting site.", required=True, type=str, dest="site_title", metavar="TITLE")
|
parser.add_argument("-t", "--site-title", help="Title of the image hosting site.", required=True, type=str, dest="site_title", metavar="TITLE")
|
||||||
parser.add_argument("-w", "--web-root-url", help="Base URL of the web root for the image hosting site.", required=True, type=str, dest="web_root_url", metavar="URL")
|
parser.add_argument("-w", "--web-root-url", help="Base URL of the web root for the image hosting site.", required=True, type=str, dest="web_root_url", metavar="URL")
|
||||||
parsed_args = parser.parse_args()
|
parsed_args = parser.parse_args()
|
||||||
_args = Args()
|
# fmt: on
|
||||||
_args.author_name = parsed_args.author_name
|
_args = Args(
|
||||||
_args.exclude_folders = parsed_args.exclude_folders
|
author_name=parsed_args.author_name,
|
||||||
_args.file_extensions = parsed_args.file_extensions
|
exclude_folders=parsed_args.exclude_folders,
|
||||||
_args.generate_webmanifest = parsed_args.generate_webmanifest
|
file_extensions=parsed_args.file_extensions,
|
||||||
_args.ignore_other_files = parsed_args.ignore_other_files
|
generate_webmanifest=parsed_args.generate_webmanifest,
|
||||||
_args.license_type = parsed_args.license_type
|
ignore_other_files=parsed_args.ignore_other_files,
|
||||||
_args.non_interactive_mode = parsed_args.non_interactive_mode
|
license_type=parsed_args.license_type,
|
||||||
_args.regenerate_thumbnails = parsed_args.regenerate_thumbnails
|
non_interactive_mode=parsed_args.non_interactive_mode,
|
||||||
_args.root_directory = parsed_args.root_directory
|
regenerate_thumbnails=parsed_args.regenerate_thumbnails,
|
||||||
_args.site_title = parsed_args.site_title
|
root_directory=parsed_args.root_directory,
|
||||||
_args.theme_path = parsed_args.theme_path
|
site_title=parsed_args.site_title,
|
||||||
_args.use_fancy_folders = parsed_args.use_fancy_folders
|
theme_path=parsed_args.theme_path,
|
||||||
_args.web_root_url = parsed_args.web_root_url
|
use_fancy_folders=parsed_args.use_fancy_folders,
|
||||||
|
web_root_url=parsed_args.web_root_url,
|
||||||
|
)
|
||||||
return _args
|
return _args
|
||||||
|
|||||||
Reference in New Issue
Block a user