From ed7623b6b472735dd98fad6423a7928bb5b8045a Mon Sep 17 00:00:00 2001 From: Flo Greistorfer Date: Thu, 4 Jul 2024 09:46:01 +0200 Subject: [PATCH] added rich help for better help readability --- README.md | 7 +- generate_html.py | 9 +-- help.svg | 184 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+), 8 deletions(-) create mode 100644 help.svg diff --git a/README.md b/README.md index 4723417..67741fa 100644 --- a/README.md +++ b/README.md @@ -23,22 +23,21 @@ - `tqdm` library - `Jinja2` library - `Pillow` library +- `rich_argparse` library ## Installation Install the required libraries using pip: ```sh -pip install numpy tqdm Jinja2 Pillow +pip install numpy tqdm Jinja2 Pillow rich-argparse ``` ## Usage The script supports several command-line options to customize its behavior. Below is the list of available options: -```sh -./generate_html.py [-h] -p ROOT -w WEBROOT -t TITLE [-i ICON] [-r] [-n] [--use-fancy-folders] [-l LICENSE] [-a AUTHOR] [-e EXTENSION] [--theme-path THEME] [--ignore-other-files] [--exclude-folders EXCLUDE] -``` +![help-preview](help.svg) ### Options diff --git a/generate_html.py b/generate_html.py index 14da109..482a7b1 100755 --- a/generate_html.py +++ b/generate_html.py @@ -10,6 +10,7 @@ import numpy as np from jinja2 import Environment, FileSystemLoader from tqdm.auto import tqdm from PIL import Image +from rich_argparse import RichHelpFormatter import cclicense @@ -20,7 +21,7 @@ FAVICON_PATH = ".static/favicon.ico" GLOBAL_CSS_PATH = ".static/global.css" DEFAULT_THEME_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), "themes", "default.css") DEFAULT_AUTHOR = "Author" -VERSION = "1.6" +VERSION = "1.6.1" 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"] @@ -48,7 +49,7 @@ class Args: def parse_arguments() -> Args: - parser = argparse.ArgumentParser(description="Generate HTML files for a static image hosting website.") + parser = argparse.ArgumentParser(description="Generate HTML files for a static image hosting website.", formatter_class=RichHelpFormatter) parser.add_argument("-p", "--root-directory", help="Root directory containing the images.", required=True, type=str, dest="root_directory") 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") parser.add_argument("-t", "--site-title", help="Title of the image hosting site.", required=True, type=str, dest="site_title") @@ -88,8 +89,6 @@ def init_globals(args: Args) -> None: args.exclude_folders = NOT_LIST args.root_directory = args.root_directory.rstrip("/") + "/" args.web_root_url = args.web_root_url.rstrip("/") + "/" - if not os.path.exists(os.path.join(args.root_directory, ".thumbnails")): - os.mkdir(os.path.join(args.root_directory, ".thumbnails")) RAW_EXTENSIONS = [ext.lower() for ext in RAW_EXTENSIONS] + [ext.upper() for ext in RAW_EXTENSIONS] @@ -221,6 +220,8 @@ def main() -> None: exit() try: + if not os.path.exists(os.path.join(args.root_directory, ".thumbnails")): + os.mkdir(os.path.join(args.root_directory, ".thumbnails")) Path(os.path.join(args.root_directory, ".lock")).touch() print("Copying static files...") diff --git a/help.svg b/help.svg new file mode 100644 index 0000000..0f8dbfb --- /dev/null +++ b/help.svg @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Usage:generate_html.py [-h-pROOT_DIRECTORY-wWEB_ROOT_URL-tSITE_TITLE [-r] [-n] +                        [-l{cc-zero,cc-by,cc-by-sa,cc-by-nd,cc-by-nc,cc-by-nc-sa,cc-by-nc-nd}] [-aAUTHOR_NAME] +                        [-eFILE_EXTENSIONS] [--theme-pathTHEME_PATH] [--use-fancy-folders] [--ignore-other-files] +                        [--exclude-folderEXCLUDE_FOLDERS] [--version] + +Generate HTML files for a static image hosting website. + +Options: +-h--helpshow this help message and exit +-p--root-directoryROOT_DIRECTORY +Root directory containing the images. +-w--web-root-urlWEB_ROOT_URL +Base URL of the web root for the image hosting site. +-t--site-titleSITE_TITLE +Title of the image hosting site. +-r--regenerate-thumbnails +Regenerate thumbnails even if they already exist. +-n--non-interactive-mode +Run in non-interactive mode, disabling progress bars. +-l--license-type{cc-zero,cc-by,cc-by-sa,cc-by-nd,cc-by-nc,cc-by-nc-sa,cc-by-nc-nd} +Specify the license type for the images. +-a--author-nameAUTHOR_NAME +Name of the author of the images. +-e--file-extensionsFILE_EXTENSIONS +File extensions to include (can be specified multiple times). +--theme-pathTHEME_PATH +Path to the CSS theme file. +--use-fancy-foldersEnable fancy folder view instead of the default Apache directory listing. +--ignore-other-filesIgnore files that do not match the specified extensions. +--exclude-folderEXCLUDE_FOLDERS +Folders to exclude from processing (can be specified multiple times). +--versionshow program's version number and exit + + + +