You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.3 KiB

import os
def generate_blueprint_structure(root_dir):
blueprint = {}
# Traverse the directory structure starting from the root_dir
for root, dirs, files in os.walk(root_dir):
# Identify the relative path to the current directory
relative_path = os.path.relpath(root, root_dir)
# Skip the root directory itself
if relative_path == ".":
continue
# Split the relative path into its components
path_parts = relative_path.split(os.sep)
# Check if we're in a directory like user/templates/user/
if len(path_parts) >= 3:
if path_parts[0] == path_parts[2]:
blueprint_name = path_parts[2]
# Initialize the dictionary for the blueprint if it doesn't exist
if blueprint_name not in blueprint:
blueprint[blueprint_name] = {"directory": [], "html_files": []}
blueprint[blueprint_name]["directory"].append(blueprint_name)
# Process files, specifically .html files, and add them to the "html_files" list
for f in files:
if f.endswith(".html"):
blueprint[blueprint_name]["html_files"].append(os.path.splitext(f)[0])
return blueprint