-
Notifications
You must be signed in to change notification settings - Fork 52
/
config_file_update_script.py
71 lines (59 loc) · 2.08 KB
/
config_file_update_script.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
import json
from pathlib import Path
import yaml
from colorama import Fore
from colorama import Style
import sys
import csv
from os import path
from os import listdir
from os.path import isfile, join
from yaml.loader import SafeLoader
## Main Script
print(Fore.YELLOW + "Started updating profile versions config file" + Style.RESET_ALL)
profile_verions_file = "./bioschemas.github.io/_data/profile_versions.yaml"
stream = open(profile_verions_file, "r")
docs = yaml.load_all(stream, yaml.FullLoader)
d = {}
for doc in docs:
try:
for k, v in doc.items():
# print(k, "->", v)
d[k] = v
# print("\n")
except Exception as e:
print("This exception occured in parsing the YAML file", e)
args = sys.argv
# For each new uploaded JSON-LD file
for arg in args:
if "jsonld" in arg.split("/"):
if "json" in arg.split("."):
arglist = arg.split("/")
profile_name = arg.split("/")[-1].split(".")[0].split("_")[0]
profile_version = arg.split("_")[1].split("v")[1].split(".json")[0]
print(
Fore.LIGHTBLUE_EX
+ "profile name and version: "
+ profile_name
+ ", "
+ profile_version
+ Style.RESET_ALL
)
if profile_name in d.keys():
print(
Fore.GREEN + "Before the change:",
str(d[profile_name]) + Style.RESET_ALL,
)
if arg.split("-")[1].split(".")[0] == "DRAFT":
d[profile_name]["latest_publication"] = profile_version
elif arg.split("-")[1].split(".")[0] == "RELEASE":
d[profile_name]["latest_release"] = profile_version
print(
Fore.LIGHTGREEN_EX + "After the update:",
str(d[profile_name]) + Style.RESET_ALL,
)
f = open(profile_verions_file, "w+")
yaml.dump(d, f, allow_unicode=True)
print(
Fore.YELLOW + "Profile versions updated " + profile_verions_file + Style.RESET_ALL
)