1
0

vcpkg_version_finder.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from pathlib import Path
  2. import json
  3. import sys
  4. if (sys.version_info.major, sys.version_info.minor) < (3, 6):
  5. raise TypeError("at least python 3.6 is required for this script")
  6. if len(sys.argv) > 1:
  7. PKG_NAME = sys.argv[1]
  8. else:
  9. raise TypeError("package name must be passed")
  10. if len(sys.argv) > 2:
  11. VCPKG_PATH = Path(sys.argv[2])
  12. else:
  13. print("no vcpkg path has been passed. Assuming vcpkg root is on the same level as this script file")
  14. VCPKG_PATH = Path(__file__).parent / 'vcpkg'
  15. if len(sys.argv) > 3:
  16. print("the arguments after the second one are ignored")
  17. if not VCPKG_PATH.exists():
  18. raise FileNotFoundError(f"dir does not exist: {VCPKG_PATH}")
  19. VERSIONS_PATH = VCPKG_PATH / 'versions'
  20. if not VERSIONS_PATH.exists():
  21. raise FileNotFoundError(f"dir does not exist: {VERSIONS_PATH}")
  22. PKG_VERSION_PATH = VERSIONS_PATH / (PKG_NAME[0] + '-')
  23. if not PKG_VERSION_PATH.exists():
  24. raise FileNotFoundError(f"dir does not exist: {PKG_VERSION_PATH}")
  25. PKG_VERSION_JSON_PATHNAME = PKG_VERSION_PATH / (PKG_NAME + '.json')
  26. if not PKG_VERSION_JSON_PATHNAME.exists:
  27. raise FileNotFoundError(f"dir does not exist: {PKG_VERSION_JSON_PATHNAME}")
  28. print(f'reading versions from {PKG_VERSION_JSON_PATHNAME}')
  29. with open(PKG_VERSION_JSON_PATHNAME) as f:
  30. pkg_versions_file = json.load(f)
  31. info_list = pkg_versions_file["versions"]
  32. versions_list = []
  33. for info in info_list:
  34. if "version-string" in info:
  35. versions_list.append(info["version-string"])
  36. elif "version" in info:
  37. versions_list.append(info["version"])
  38. elif "version-date" in info:
  39. versions_list.append(info["version-date"])
  40. elif "version-semver" in info:
  41. versions_list.append(info["version-semver"])
  42. else:
  43. raise KeyError(info)
  44. versions_set = sorted(set(versions_list), reverse=True)
  45. for version in versions_set:
  46. print(version)