reroot.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import os
  9. import subprocess
  10. import argparse
  11. import sys
  12. restricted_platforms = ['Provo', 'Salem']
  13. def move_root(current_source_dir, csd_to_platform_parent, platform_dir, ly_dir):
  14. cwd = os.getcwd()
  15. if not ly_dir:
  16. ly_dir = cwd
  17. ly_to_csd = os.path.relpath(os.path.join(cwd, current_source_dir), ly_dir)
  18. platform_parent_dir = os.path.normpath(os.path.join(current_source_dir, csd_to_platform_parent, platform_dir))
  19. for p in os.listdir(platform_parent_dir):
  20. if p in restricted_platforms:
  21. source_dir = os.path.normpath(os.path.join(platform_parent_dir, p))
  22. dest_dir = os.path.normpath(os.path.join(ly_dir, 'restricted', p, ly_to_csd, csd_to_platform_parent))
  23. for root, _, files in os.walk(source_dir):
  24. for f in files:
  25. old = os.path.join(root, f)
  26. source_to_old = os.path.relpath(old, source_dir)
  27. new = os.path.join(dest_dir, source_to_old)
  28. subprocess.run(['p4', 'move', '-r', old, new])
  29. parser = argparse.ArgumentParser(description='Re-root restricted platform files')
  30. parser.add_argument('source_path', type=str, help='Relative path to the source tree of restricted files to move')
  31. parser.add_argument('--pal', type=str, default='Platform', help='Name of folder that contains the pal-ified folders (defaults to "Platform")')
  32. parser.add_argument('--path-to-pal', type=str, default='', help='Additional path between source path and the pal folder (defaults to no additional path)')
  33. parser.add_argument('--out-dir', type=str, help='root directory that holds the "restricted" folder. Defaults to current working directory')
  34. args = parser.parse_args()
  35. move_root(args.source_path, args.path_to_pal, args.pal, args.out_dir)