extract_low_level.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import argparse
  2. import sys
  3. import subprocess
  4. import json
  5. from pathlib import Path
  6. # Add the utils directory to the Python path
  7. utils_path = Path(__file__).parent / 'utils'
  8. sys.path.append(str(utils_path))
  9. from config_utils import load_config
  10. def run_subprocess(script_name, input_dir, output_dir, indent=None, shrink=False, ignored_folders=None):
  11. """Helper function to run a parser subprocess."""
  12. script_path = Path(__file__).parent / "parsers" / script_name
  13. command = [
  14. sys.executable,
  15. str(script_path),
  16. "--input",
  17. str(input_dir),
  18. "--output",
  19. str(output_dir)
  20. ]
  21. # Pass indent and shrink arguments to subparsers.
  22. # This assumes the subparsers have been updated to accept them.
  23. if indent is not None:
  24. command.extend(["--indent", str(indent)])
  25. if shrink:
  26. command.append("--shrink-json")
  27. if ignored_folders:
  28. command.extend(["--ignored-folders", json.dumps(ignored_folders)])
  29. try:
  30. result = subprocess.run(command, check=True, text=True, capture_output=True, encoding='utf-8')
  31. if result.stdout:
  32. print(result.stdout)
  33. if result.stderr:
  34. print(result.stderr, file=sys.stderr)
  35. except subprocess.CalledProcessError as e:
  36. print(f"--- ERROR in {script_name} ---")
  37. print(e.stdout)
  38. print(e.stderr, file=sys.stderr)
  39. print(f"--- End of Error ---")
  40. except FileNotFoundError:
  41. print(f"--- ERROR: Script not found at {script_path} ---", file=sys.stderr)
  42. def main():
  43. """
  44. Main function to orchestrate the low-level data extraction pipeline.
  45. """
  46. parser = argparse.ArgumentParser(
  47. description="Orchestrates a pipeline of parsers for a detailed data breakdown."
  48. )
  49. parser.add_argument("--input", type=str, required=True, help="The root directory of the target Unity project.")
  50. parser.add_argument("--output", type=str, required=True, help="The directory where the generated output folder will be saved.")
  51. args = parser.parse_args()
  52. # --- Load Configuration ---
  53. config = load_config()
  54. ignored_folders = config.get('ignored_folders', [])
  55. shrink_json = config.get('shrink_json', False)
  56. indent_level = config.get('indentation_level', 4)
  57. input_dir = Path(args.input).resolve()
  58. output_dir = Path(args.output).resolve()
  59. if not input_dir.is_dir():
  60. print(f"Error: Input path '{input_dir}' is not a valid directory.", file=sys.stderr)
  61. sys.exit(1)
  62. low_level_output_dir = output_dir / "LowLevel"
  63. low_level_output_dir.mkdir(parents=True, exist_ok=True)
  64. print(f"Output will be saved to: {low_level_output_dir}")
  65. # --- Run Extraction Pipeline ---
  66. # Pass all relevant config options to the subparsers.
  67. run_subprocess("copy_scripts.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
  68. run_subprocess("copy_shaders.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
  69. run_subprocess("parse_project_settings.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
  70. run_subprocess("parse_generic_assets.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
  71. run_subprocess("parse_scenes_and_prefabs.py", input_dir, low_level_output_dir, indent_level, shrink_json, ignored_folders)
  72. print("\nLow-level extraction pipeline complete.")
  73. if __name__ == "__main__":
  74. main()