export_all_patches.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. import argparse
  3. import json
  4. import os
  5. import warnings
  6. from lib import git
  7. def export_patches(target, dry_run):
  8. repo = target.get('repo')
  9. if not os.path.exists(repo):
  10. warnings.warn('repo not found: %s' % repo)
  11. return
  12. git.export_patches(
  13. dry_run=dry_run,
  14. grep=target.get('grep'),
  15. out_dir=target.get('patch_dir'),
  16. repo=repo
  17. )
  18. def export_config(config, dry_run):
  19. for target in config:
  20. export_patches(target, dry_run)
  21. def parse_args():
  22. parser = argparse.ArgumentParser(description='Export Electron patches')
  23. parser.add_argument('config', nargs='+',
  24. type=argparse.FileType('r'),
  25. help='patches\' config(s) in the JSON format')
  26. parser.add_argument("-d", "--dry-run",
  27. help="Checks whether the exported patches need to be updated.",
  28. default=False, action='store_true')
  29. return parser.parse_args()
  30. def main():
  31. configs = parse_args().config
  32. dry_run = parse_args().dry_run
  33. for config_json in configs:
  34. export_config(json.load(config_json), dry_run)
  35. if __name__ == '__main__':
  36. main()