-
Notifications
You must be signed in to change notification settings - Fork 297
/
update.py
executable file
·142 lines (135 loc) · 3.42 KB
/
update.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
#!/usr/bin/env python3
import requests
import json
import os
from datetime import datetime
import argparse
parser = argparse.ArgumentParser(prog="OpenModelica index.json creator")
parser.add_argument('--test', action="store_true")
parser.add_argument('filenameprefix')
args = parser.parse_args()
data = requests.get('https://libraries.openmodelica.org/index/v1/index.json').json()
desired = {
"BioChem": {"1.0.1+msl.3.2.1"},
"Complex": {
"3.2.1+maint.om",
"3.2.2+maint.om",
"3.2.3+maint.om",
"4.0.0+maint.om"
},
"Modelica": {
"2.2.2+maint.om",
"3.1.0+maint.om",
"3.2.1+maint.om",
"3.2.2+maint.om",
"3.2.3+maint.om",
"4.0.0+maint.om"
},
"ModelicaServices": {
"1.0.0",
"3.2.1+maint.om",
"3.2.2+maint.om",
"3.2.3+maint.om",
"4.0.0+maint.om"
},
"ModelicaTest": {
"3.2.3+maint.om"
},
"ModelicaCompliance": {
"3.2.0-master"
},
"Modelica_DeviceDrivers": {
"1.8.2"
},
"Modelica_Synchronous": {
"0.92.2"
},
"ScalableTestSuite": {
"2.2.0"
},
"SiemensPower": {
"2.1.0-beta",
"2.2.0",
"OMCtest"
},
"ThermoPower": {
"3.1.0-master"
},
"ThermoSysPro": {
"3.2.0"
},
"WasteWater": {
"2.1.0"
}
} if args.test else {
"Complex": {
"4.0.0+maint.om"
},
"Modelica": {
"3.2.3+maint.om",
"4.0.0+maint.om"
},
"ModelicaServices": {
"4.0.0+maint.om"
},
"ObsoleteModelica4": { # Used by MSL 3 to 4 conversion scripts
"4.0.0+maint.om"
},
"ModelicaReference": {
"4.0.0+maint.om"
}
}
newdata = {}
for key in data["libs"].keys():
if key not in desired:
continue
newdata[key] = {"versions": {}}
versions = data["libs"][key]["versions"]
for version in versions.keys():
if version not in desired[key]:
continue
newdata[key]["versions"][version] = versions[version]
now = datetime.now()
stamp = now.strftime("%Y%m%d%H%M%S.stamp")
with open(args.filenameprefix + "index.mos", "w") as fout:
fout.write('''
setEnvironmentVar("HOME", OpenModelica.Scripting.cd());
setEnvironmentVar("APPDATA", OpenModelica.Scripting.cd());
getEnvironmentVar("HOME");
getErrorString();
setModelicaPath(OpenModelica.Scripting.cd() + "/.openmodelica/libraries/");
getModelicaPath();
echo(false);
OpenModelica.Scripting.mkdir(".openmodelica");
if not OpenModelica.Scripting.mkdir(".openmodelica/libraries/") then
print("\\nmkdir failed\\n");
print(getErrorString());
exit(1);
end if;
vers:=OpenModelica.Scripting.getAvailablePackageVersions(Modelica, "3.2.3");
if size(vers,1) <> 1 then
print("getAvailablePackageVersions(Modelica, \\"3.2.3\\") returned " + String(size(vers,1)) + " results\\n");
print(getErrorString());
exit(1);
end if;
if vers[1] <> "3.2.3+maint.om" then
print("getAvailablePackageVersions(Modelica, \\"3.2.3\\") returned " + vers[1] + "\\n");
print(getErrorString());
exit(1);
end if;
''')
for lib in desired.keys():
for version in desired[lib]:
fout.write('''if not installPackage(%s, "%s", exactMatch=true) then
print("%s %s failed.\\n");
print(getErrorString());
exit(1);
else
print("Installed: %s %s\\n");
end if;
''' % (lib, version, lib, version, lib, version))
fout.write('system("touch .openmodelica/%s")' % stamp)
with open(args.filenameprefix + "index.json", "w") as fout:
fout.write(json.dumps({"libs":newdata,"mirrors":["https://libraries.openmodelica.org/cache/"]}, indent=2))
with open("Makefile.version", "w") as fout:
fout.write('STAMP=%s' % stamp)