apply_all_patches.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. import argparse
  3. import json
  4. import os
  5. import warnings
  6. from lib import git
  7. from lib.patches import patch_from_dir
  8. THREEWAY = "ELECTRON_USE_THREE_WAY_MERGE_FOR_PATCHES" in os.environ
  9. def apply_patches(target):
  10. repo = target.get('repo')
  11. if not os.path.exists(repo):
  12. warnings.warn(f'repo not found: {repo}')
  13. return
  14. patch_dir = target.get('patch_dir')
  15. git.import_patches(
  16. committer_email="scripts@electron",
  17. committer_name="Electron Scripts",
  18. patch_data=patch_from_dir(patch_dir),
  19. repo=repo,
  20. threeway=THREEWAY,
  21. )
  22. def apply_config(config):
  23. for target in config:
  24. apply_patches(target)
  25. def parse_args():
  26. parser = argparse.ArgumentParser(description='Apply Electron patches')
  27. parser.add_argument('config', nargs='+',
  28. type=argparse.FileType('r'),
  29. help='patches\' config(s) in the JSON format')
  30. return parser.parse_args()
  31. def main():
  32. for config_json in parse_args().config:
  33. apply_config(json.load(config_json))
  34. if __name__ == '__main__':
  35. main()