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