# generate_manifest.py import os import json import hashlib from datetime import datetime DWG_FOLDER = "/app/dwg_files" DATABASE_FOLDER = "/app/database_files" MANIFEST_FILE = "/app/manifest.json" def generate_file_hash(file_path): """Generate SHA256 hash for a file.""" hasher = hashlib.sha256() with open(file_path, "rb") as f: while chunk := f.read(8192): hasher.update(chunk) return hasher.hexdigest() def process_directory(directory, manifest, prefix=""): """Process a directory and add its files to the manifest.""" extensions = [".dwg", ".txt", ".csv"] # Whitelist of allowed files without extensions (matches app.py configuration) allowed_no_extension_files = ["version"] for root, _, files in os.walk(directory): for file in files: file_lower = file.lower() file_path = os.path.join(root, file) rel_path = os.path.relpath(file_path, directory) # Check if file has allowed extension or is in whitelist for files without extensions has_allowed_extension = any(file_lower.endswith(ext) for ext in extensions) is_allowed_no_extension = not os.path.splitext(file)[1] and file in allowed_no_extension_files if has_allowed_extension or is_allowed_no_extension: manifest[rel_path] = { "size": os.path.getsize(file_path), "modified": os.path.getmtime(file_path), "hash": generate_file_hash(file_path), "path": rel_path, "remote_prefix": prefix } def generate_manifest(): """Scans the directories and creates a manifest file.""" manifest = {} # Process DWG files directory if os.path.exists(DWG_FOLDER): process_directory(DWG_FOLDER, manifest, "dwg_files") # Process database files directory if os.path.exists(DATABASE_FOLDER): process_directory(DATABASE_FOLDER, manifest, "database_files") with open(MANIFEST_FILE, "w") as f: json.dump(manifest, f, indent=4) print("✅ Manifest updated successfully.") if __name__ == "__main__": generate_manifest()