-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate_castxml_version.py
170 lines (130 loc) · 5.26 KB
/
update_castxml_version.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"""Command line executable allowing to update CastXMLUrls.cmake
given a CMake version.
"""
import argparse
import contextlib
import os
import re
import textwrap
try:
import girder_client
except ImportError:
raise SystemExit(
"girder_client not available: "
"consider installing it running 'pip install girder-client'"
)
ROOT_DIR = os.path.join(os.path.dirname(__file__), "..")
@contextlib.contextmanager
def _log(txt, verbose=True):
if verbose:
print(txt)
yield
if verbose:
print("%s - done" % txt)
def get_archive_urls_and_shas(version, verbose=False):
host_url = 'https://data.kitware.com'
folder_id = '57b5de948d777f10f2696370'
with _log("Collecting URLs and SHAs from '%s/#folder/%s'" % (host_url, folder_id)):
api_url = '%s/api/v1' % host_url
gc = girder_client.GirderClient(apiUrl=api_url)
folders = gc.listFolder('57b5de948d777f10f2696370')
archive_folder_ids = [folder['_id'] for folder in folders if folder['name'] == "v%s" % version]
assert len(archive_folder_ids) == 1
items = gc.listItem(archive_folder_ids[0])
expected_files = {
"castxml-linux.tar.gz": "linux64_binary",
"castxml-macosx.tar.gz": "macosx_binary",
"castxml-windows.zip": "win64_binary",
}
# Get download URL and SHA512 for each file
urls_and_shas = {}
for item in items:
files = list(gc.listFile(item['_id']))
assert len(files) == 1
file_id = files[0]['_id']
file = files[0]['name']
sha = files[0]['sha512']
url = '%s/file/%s/download' % (api_url, file_id)
if file in expected_files:
identifier = expected_files[file]
urls_and_shas[identifier] = (url, sha)
if verbose:
print("[%s]\n%s\n%s\n" % (identifier, url, sha))
assert len(urls_and_shas) == len(expected_files)
return urls_and_shas
def generate_cmake_variables(urls_and_shas):
template_inputs = {}
for var_prefix, urls_and_shas in urls_and_shas.items():
template_inputs["%s_url" % var_prefix] = urls_and_shas[0]
template_inputs["%s_sha512" % var_prefix] = urls_and_shas[1]
cmake_variables = textwrap.dedent("""
#-----------------------------------------------------------------------------
# CastXML binaries
set(linux32_binary_url "NA") # Linux 32-bit binaries not available
set(linux32_binary_sha512 "NA")
set(linux64_binary_url "{linux64_binary_url}")
set(linux64_binary_sha512 "{linux64_binary_sha512}")
set(macosx_binary_url "{macosx_binary_url}")
set(macosx_binary_sha512 "{macosx_binary_sha512}")
set(win64_binary_url "{win64_binary_url}")
set(win64_binary_sha512 "{win64_binary_sha512}")
# See https://github.com/CastXML/CastXML-python-distributions/issues/5
set(win32_binary_url "${{win64_binary_url}}")
set(win32_binary_sha512 "${{win64_binary_sha512}}")
""").format(**template_inputs)
return cmake_variables
def update_urls_script(version):
content = generate_cmake_variables(
get_archive_urls_and_shas(version))
urls_filename = "CastXMLUrls.cmake"
urls_filepath = os.path.join(ROOT_DIR, urls_filename)
msg = "Updating '%s' with CastXML version %s" % (urls_filename, version)
with _log(msg), open(urls_filepath, "w") as urls_file:
urls_file.write(content)
def _update_file(filepath, regex, replacement, verbose=True):
msg = "Updating %s" % os.path.relpath(filepath, ROOT_DIR)
with _log(msg, verbose=verbose):
pattern = re.compile(regex)
with open(filepath, 'r') as doc_file:
lines = doc_file.readlines()
updated_content = []
for line in lines:
updated_content.append(
re.sub(pattern, replacement, line))
with open(filepath, "w") as doc_file:
doc_file.writelines(updated_content)
def update_docs(version):
pattern = re.compile(r"CastXML \d\.\d\.\d")
replacement = "CastXML %s" % version
_update_file(
os.path.join(ROOT_DIR, "README.md"),
pattern, replacement)
pattern = re.compile(r"\d\.\d\.\d")
replacement = version
_update_file(
os.path.join(ROOT_DIR, "docs/update_castxml_version.rst"),
pattern, replacement)
def update_tests(version):
pattern = re.compile(r'expected_version = "\d.(\d)+.\d"')
replacement = 'expected_version = "%s"' % version
_update_file(os.path.join(
ROOT_DIR, "tests/test_distribution.py"), pattern, replacement)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'version', metavar='CASTXML_VERSION', type=str,
help='CastXML version of the form X.Y.Z'
)
parser.add_argument(
'--collect-only', action='store_true',
help='If specified, only display the archive URLs and associated hashsums'
)
args = parser.parse_args()
if args.collect_only:
get_archive_urls_and_shas(args.version, verbose=True)
else:
update_urls_script(args.version)
update_docs(args.version)
update_tests(args.version)
if __name__ == "__main__":
main()