copy_scripts.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import argparse
  2. import sys
  3. import shutil
  4. import json
  5. from pathlib import Path
  6. # Add the utils directory to the Python path
  7. utils_path = Path(__file__).parent.parent / 'utils'
  8. sys.path.append(str(utils_path))
  9. from file_utils import find_files_by_extension
  10. def main():
  11. parser = argparse.ArgumentParser(description="Copies all C# scripts (.cs) to the target directory.")
  12. parser.add_argument("--input", type=str, required=True, help="The root directory of the target Unity project.")
  13. parser.add_argument("--output", type=str, required=True, help="The directory where the output will be saved.")
  14. # Add arguments that are passed by the orchestrator but not used by this script
  15. parser.add_argument("--indent", type=int, default=None)
  16. parser.add_argument("--shrink-json", action='store_true')
  17. parser.add_argument("--ignored-folders", type=str, default='[]', help='JSON string of folders to ignore.')
  18. args = parser.parse_args()
  19. try:
  20. ignored_folders = json.loads(args.ignored_folders)
  21. except json.JSONDecodeError:
  22. print("Warning: Could not parse ignored-folders JSON string. Defaulting to empty list.", file=sys.stderr)
  23. ignored_folders = []
  24. input_dir = Path(args.input).resolve()
  25. output_dir = Path(args.output).resolve()
  26. assets_dir = input_dir / "Assets"
  27. output_assets_dir = output_dir / "Assets"
  28. if not assets_dir.is_dir():
  29. return
  30. cs_files = find_files_by_extension(str(assets_dir), '.cs', ignored_folders=ignored_folders, project_root=input_dir)
  31. if not cs_files:
  32. print("No C# scripts found to copy.")
  33. return
  34. print(f"\n--- Starting Script Handling ---")
  35. print(f"Found {len(cs_files)} C# script files to copy.")
  36. for script_path_str in cs_files:
  37. script_path = Path(script_path_str)
  38. relative_path = script_path.relative_to(assets_dir)
  39. destination_path = output_assets_dir / relative_path
  40. destination_path.parent.mkdir(parents=True, exist_ok=True)
  41. try:
  42. shutil.copy(script_path, destination_path)
  43. except IOError as e:
  44. print(f"Error copying {script_path} to {destination_path}: {e}", file=sys.stderr)
  45. print("Script copying complete.")
  46. if __name__ == "__main__":
  47. main()