123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import argparse
- import sys
- import subprocess
- import json
- from pathlib import Path
- # Add the utils directory to the Python path
- utils_path = Path(__file__).parent / 'utils'
- sys.path.append(str(utils_path))
- from config_utils import load_config
- def run_subprocess(script_name, input_dir, output_dir, indent=None, shrink=False, ignored_folders=None):
- """Helper function to run a parser subprocess."""
- script_path = Path(__file__).parent / "parsers" / script_name
- command = [
- sys.executable,
- str(script_path),
- "--input",
- str(input_dir),
- "--output",
- str(output_dir)
- ]
-
- # Pass indent and shrink arguments to subparsers.
- # This assumes the subparsers have been updated to accept them.
- if indent is not None:
- command.extend(["--indent", str(indent)])
- if shrink:
- command.append("--shrink-json")
-
- if ignored_folders:
- command.extend(["--ignored-folders", json.dumps(ignored_folders)])
- try:
- result = subprocess.run(command, check=True, text=True, capture_output=True, encoding='utf-8')
- if result.stdout:
- print(result.stdout)
- if result.stderr:
- print(result.stderr, file=sys.stderr)
- except subprocess.CalledProcessError as e:
- print(f"--- ERROR in {script_name} ---")
- print(e.stdout)
- print(e.stderr, file=sys.stderr)
- print(f"--- End of Error ---")
- except FileNotFoundError:
- print(f"--- ERROR: Script not found at {script_path} ---", file=sys.stderr)
- def main():
- """
- Main function to orchestrate the low-level data extraction pipeline.
- """
- parser = argparse.ArgumentParser(
- description="Orchestrates a pipeline of parsers for a detailed data breakdown."
- )
- parser.add_argument("--input", type=str, required=True, help="The root directory of the target Unity project.")
- parser.add_argument("--output", type=str, required=True, help="The directory where the generated output folder will be saved.")
- args = parser.parse_args()
- # --- Load Configuration ---
- config = load_config()
- ignored_folders = config.get('ignored_folders', [])
- shrink_json = config.get('shrink_json', False)
- indent_level = config.get('indentation_level', 4)
- input_dir = Path(args.input).resolve()
- output_dir = Path(args.output).resolve()
- if not input_dir.is_dir():
- print(f"Error: Input path '{input_dir}' is not a valid directory.", file=sys.stderr)
- sys.exit(1)
- low_level_output_dir = output_dir / "LowLevel"
- low_level_output_dir.mkdir(parents=True, exist_ok=True)
- print(f"Output will be saved to: {low_level_output_dir}")
- # --- Run Extraction Pipeline ---
- # Pass all relevant config options to the subparsers.
- run_subprocess("copy_scripts.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
- run_subprocess("copy_shaders.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
- run_subprocess("parse_project_settings.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
- run_subprocess("parse_generic_assets.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
- run_subprocess("parse_scenes_and_prefabs.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
- print("\nLow-level extraction pipeline complete.")
- if __name__ == "__main__":
- main()
|