auto-archiver/scripts/generate_settings_schema.py

43 wiersze
1.6 KiB
Python
Czysty Zwykły widok Historia

2025-02-26 17:02:49 +00:00
import json
import os
2025-02-26 17:02:49 +00:00
2025-02-21 18:04:48 +00:00
from auto_archiver.core.module import ModuleFactory
from auto_archiver.core.consts import MODULE_TYPES
2025-02-26 17:02:49 +00:00
class SchemaEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(obj)
return json.JSONEncoder.default(self, obj)
2025-02-21 18:04:48 +00:00
# Get available modules
module_factory = ModuleFactory()
available_modules = module_factory.available_modules()
modules_by_type = {}
# Categorize modules by type
for module in available_modules:
2025-02-21 18:54:27 +00:00
for type in module.manifest.get('type', []):
2025-02-21 18:04:48 +00:00
modules_by_type.setdefault(type, []).append(module)
all_modules_ordered_by_type = sorted(available_modules, key=lambda x: (MODULE_TYPES.index(x.type[0]), not x.requires_setup))
2025-02-27 21:23:38 +00:00
output_schema = {
2025-02-26 17:02:49 +00:00
'modules': dict((module.name,
{
'name': module.name,
'display_name': module.display_name,
'manifest': module.manifest,
'configs': module.configs or None
}
) for module in all_modules_ordered_by_type),
'steps': dict((f"{module_type}s", [module.name for module in modules_by_type[module_type]]) for module_type in MODULE_TYPES),
2025-02-26 17:02:49 +00:00
'configs': [m.name for m in all_modules_ordered_by_type if m.configs],
'module_types': MODULE_TYPES,
}
current_file_dir = os.path.dirname(os.path.abspath(__file__))
output_file = os.path.join(current_file_dir, 'settings/src/schema.json')
2025-02-21 18:04:48 +00:00
with open(output_file, 'w') as file:
2025-02-27 21:23:38 +00:00
json.dump(output_schema, file, indent=4, cls=SchemaEncoder)