From 7562938151e833685c861ef5d09c7f0c64e335d4 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Fri, 21 Feb 2025 18:04:48 +0000 Subject: [PATCH] Proof of concept for settings page --- .gitignore | 1 + scripts/generate_settings_page.py | 83 ++++++++++++++++++++++++ scripts/settings.html | 103 ++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 scripts/generate_settings_page.py create mode 100644 scripts/settings.html diff --git a/.gitignore b/.gitignore index 701de43..4b8779f 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ dist* docs/_build/ docs/source/autoapi/ docs/source/modules/autogen/ +scripts/settings_page.html diff --git a/scripts/generate_settings_page.py b/scripts/generate_settings_page.py new file mode 100644 index 0000000..2b74cf9 --- /dev/null +++ b/scripts/generate_settings_page.py @@ -0,0 +1,83 @@ +import os +from auto_archiver.core.module import ModuleFactory +from auto_archiver.core.consts import MODULE_TYPES +import jinja2 + +# Get available modules +module_factory = ModuleFactory() +available_modules = module_factory.available_modules() + +modules_by_type = {} +# Categorize modules by type +for module in available_modules: + for type in module.type: + modules_by_type.setdefault(type, []).append(module) + + +module_sections = "" +# Add module sections +for module_type in MODULE_TYPES: + module_sections += f"

{module_type}

" + for module in modules_by_type[module_type]: + module_name = module.name + module_sections += f""" +
+ + +
+ """ + module_sections += "
" + +# Add module configuration sections + +all_modules_ordered_by_type = sorted(available_modules, key=lambda x: (MODULE_TYPES.index(x.type[0]), not x.requires_setup)) + +module_configs = "" + +for module in all_modules_ordered_by_type: + if not module.configs: + continue + module_configs += f"

{module.display_name} Configuration

" + for option, value in module.configs.items(): + # create a human readable label + option = option.replace('_', ' ').title() + + # type - if value has 'choices', then it's a select + if 'choices' in value: + module_configs += f""" +
+ +
" + elif value.get('type') == 'bool' or isinstance(value.get('default', None), bool): + module_configs += f""" +
+ + +
+ """ + else: + module_configs += f""" +
+ + +
+ """ + module_configs += "
" + +# format the settings.html jinja page with the module sections and module configuration sections +settings_page = "settings.html" +template_loader = jinja2.FileSystemLoader(searchpath="./") +template_env = jinja2.Environment(loader=template_loader) +template = template_env.get_template(settings_page) +html_content = template.render(module_sections=module_sections, module_configs=module_configs) + +# Write HTML content to file +output_file = '/Users/patrick/Developer/auto-archiver/scripts/settings_page.html' +with open(output_file, 'w') as file: + file.write(html_content) + +print(f"Settings page generated at {output_file}") \ No newline at end of file diff --git a/scripts/settings.html b/scripts/settings.html new file mode 100644 index 0000000..bd11edd --- /dev/null +++ b/scripts/settings.html @@ -0,0 +1,103 @@ + + + + + + Module Settings + + + + + +

Module Settings

+
+ + + +

Steps

+ + {{module_sections}} + +

Module Configuration Section

+ {{module_configs}} + + +
+ + \ No newline at end of file