parse_packagecloud_dist_id.py 995 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. '''
  3. Parse the PackageCloud distributions JSON data to get a dist ID for uploads.
  4. This takes the JSON distributions data from Packagecloud on stdin and
  5. the package format, distribution name and version as arguments, and
  6. prints either an error message or the parsed distribution ID based on
  7. the arguments.
  8. '''
  9. import json
  10. import sys
  11. fmt = sys.argv[1] # The package format ('deb' or 'rpm')
  12. distro = sys.argv[2] # The distro name
  13. version = sys.argv[3] # The distro version
  14. print(fmt)
  15. print(distro)
  16. print(version)
  17. data = json.load(sys.stdin)
  18. versions = []
  19. for entry in data[fmt]:
  20. if entry['display_name'] == distro:
  21. versions = entry['versions']
  22. break
  23. if not versions:
  24. print('Could not find version information for the requested distribution.')
  25. sys.exit(-1)
  26. for entry in versions:
  27. if entry['version_number'] == version:
  28. print(entry['id'])
  29. sys.exit(0)
  30. print('Unable to find id for requested version.')
  31. sys.exit(-1)