extract_low_level.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import argparse
  2. import sys
  3. import subprocess
  4. from pathlib import Path
  5. def run_subprocess(script_name, input_dir, output_dir, indent=None):
  6. """Helper function to run a parser subprocess."""
  7. script_path = Path(__file__).parent / "parsers" / script_name
  8. command = [
  9. sys.executable,
  10. str(script_path),
  11. "--input",
  12. str(input_dir),
  13. "--output",
  14. str(output_dir)
  15. ]
  16. if indent is not None:
  17. command.extend(["--indent", str(indent)])
  18. try:
  19. subprocess.run(command, check=True, text=True, capture_output=True)
  20. except subprocess.CalledProcessError as e:
  21. print(f"--- ERROR in {script_name} ---")
  22. print(e.stdout)
  23. print(e.stderr)
  24. print(f"--- End of Error ---")
  25. def main():
  26. """
  27. Main function to orchestrate the low-level data extraction pipeline.
  28. """
  29. parser = argparse.ArgumentParser(
  30. description="Orchestrates a pipeline of parsers for a detailed data breakdown."
  31. )
  32. parser.add_argument("--input", type=str, required=True, help="The root directory of the target Unity project.")
  33. parser.add_argument("--output", type=str, required=True, help="The directory where the output folder will be saved.")
  34. parser.add_argument("--indent", type=int, default=None, help="Indentation level for JSON output.")
  35. args = parser.parse_args()
  36. input_dir = Path(args.input).resolve()
  37. output_dir = Path(args.output).resolve()
  38. if not input_dir.is_dir():
  39. print(f"Error: Input path '{input_dir}' is not a valid directory.", file=sys.stderr)
  40. sys.exit(1)
  41. low_level_output_dir = output_dir / "LowLevel"
  42. low_level_output_dir.mkdir(parents=True, exist_ok=True)
  43. print(f"Output will be saved to: {low_level_output_dir}")
  44. # --- Run Extraction Pipeline ---
  45. run_subprocess("copy_scripts.py", input_dir, low_level_output_dir, args.indent)
  46. run_subprocess("copy_shaders.py", input_dir, low_level_output_dir, args.indent)
  47. run_subprocess("parse_project_settings.py", input_dir, low_level_output_dir, args.indent)
  48. run_subprocess("parse_generic_assets.py", input_dir, low_level_output_dir, args.indent)
  49. run_subprocess("parse_scenes_and_prefabs.py", input_dir, low_level_output_dir, args.indent)
  50. print("\nLow-level extraction pipeline complete.")
  51. if __name__ == "__main__":
  52. main()