-
Notifications
You must be signed in to change notification settings - Fork 12
/
update_metadata.py
54 lines (40 loc) · 1.2 KB
/
update_metadata.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
import copy
import json
import os
import re
import sys
plugin_file = "{0}-install.json"
def print_usage():
usage = """
Usage:
python update_metada.py <plugin_name> <new_version>
Example:
python update_metdata.py java 0.7.4
python update_metdata.py html-report 1.2.3
"""
print(usage)
exit(1)
def update_version(url, old_version, new_version):
return url.replace(old_version, new_version)
def update_urls(metadata, version):
ov = metadata["version"]
metadata["version"] = version
urls = metadata["DownloadUrls"]
for arch in urls:
for platform in urls[arch]:
new_url = update_version(urls[arch][platform], ov, version)
urls[arch][platform] = new_url
def update_matada(plugin, version):
file = plugin_file.format(plugin)
with open(file, 'r') as f:
data = json.load(f)
metadata = copy.deepcopy(data["versions"][0])
update_urls(metadata, version)
data["versions"] = [metadata] + data["versions"]
os.remove(file)
with open(file, "w") as f:
json.dump(data, f, indent=4)
if __name__ == "__main__":
if len(sys.argv) < 3:
print_usage()
update_matada(sys.argv[1], sys.argv[2])