add_release_repo.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import argparse
  4. import sys
  5. import yaml
  6. from sort_yaml import sort_yaml_data
  7. def add_release_repository(yaml_file, name, url, version):
  8. data = yaml.safe_load(open(yaml_file, 'r'))
  9. if data['type'] == 'gbp':
  10. add_release_repository_fuerte(yaml_file, data, name, url, version)
  11. return
  12. raise RuntimeError('The passed .yaml file is not of type "gbp" and it is not supported for Groovy or newer')
  13. def add_release_repository_fuerte(yaml_file, data, name, url, version):
  14. if name in data['repositories']:
  15. raise RuntimeError('Repository with name "%s" is already in the .yaml file' % name)
  16. data['repositories'][name] = {
  17. 'url': url,
  18. 'version': version,
  19. }
  20. sort_yaml_data(data)
  21. with open(yaml_file, 'w') as out_file:
  22. yaml.dump(data, out_file, default_flow_style=False)
  23. if __name__ == "__main__":
  24. parser = argparse.ArgumentParser(description='Insert a git-buildpackage repository into the .yaml file.')
  25. parser.add_argument('yaml_file', help='The yaml file to update')
  26. parser.add_argument('name', help='The unique name of the repo')
  27. parser.add_argument('url', help='The url of the GBP repository')
  28. parser.add_argument('version', help='The version')
  29. args = parser.parse_args()
  30. try:
  31. add_release_repository(args.yaml_file, args.name, args.url, args.version)
  32. except Exception as e:
  33. print(str(e), file=sys.stderr)
  34. exit(1)