forked from IfcOpenShell/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilds.py
212 lines (167 loc) · 6.35 KB
/
builds.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import re
from github import Github
from werkzeug.contrib.cache import SimpleCache
def get_commit_comment(branch):
def has_comments(commit):
comments = commit.get_comments()
for comment in comments:
if comment.user.login == "IfcOpenBot":
if "v0.6.0" in comment.body:
return True
def get_commit_with_comment(commit):
if has_comments(commit):
return commit
for acommit in commit.parents:
return get_commit_with_comment(acommit)
g = Github()
repo = g.get_repo("IfcOpenBot/IfcOpenShell")
# commits on the website are currently hardcoded
if branch == "master":
commit = repo.get_commit("8625aab5f0c2c4752eb10ad20daee744547b377e")
else:
commit = repo.get_commit("517b81950478e2eb580b24cd03c5a9907f23979c")
head_commit = repo.get_branch(branch).commit
commit = get_commit_with_comment(head_commit)
return list(commit.get_comments())[0].body
cache = SimpleCache()
def get_commit_comment_cached(branch):
rv = cache.get(branch)
if rv is None:
rv = get_commit_comment(branch)
cache.set(branch, rv, timeout=60 * 60 * 8)
return rv
def build_dict(first_comment_body):
d = {
"IfcBlender": [],
"IfcGeomServer": [],
"IfcConvert": [],
"ifcopenshell-python": [],
}
m = re.findall(r"\((.*?)\)", first_comment_body)
for e in m:
if "ifcblender" in e:
d["IfcBlender"].append(e)
if "IfcConvert" in e:
d["IfcConvert"].append(e)
if "IfcGeomServer" in e:
d["IfcGeomServer"].append(e)
if "ifcopenshell-python" in e:
d["ifcopenshell-python"].append(e)
return d
def os_version(nbits):
return " %sbit" % nbits
def get_os(s, nm):
if "linux" in s:
return " " + "Linux"
if "os" in s:
return " " + "OSX"
if "win" in s:
return " " + "Windows"
def get(product, branch):
try:
first_comment_body = get_commit_comment_cached(branch)
urls = build_dict(first_comment_body)[product]
names = []
for i in range(len(urls)):
final_dict = {"Linux": [], "OSX": [], "Windows": []}
if product == "IfcGeomServer":
idx = urls[i].index(".zip")
nbits = urls[i][idx - 2 : idx]
nm = os_version(nbits)
nm += get_os(urls[i])
names.append("IfcGeomServer" + " " + nm)
if product == "IfcBlender":
if branch == "v0.6.0":
nb = re.search(r"(blender-(.*)-v0\.6\.0)", urls[i])
nb = nb.group()
if branch == "master":
nb = re.search(r"(blender-(.*)-master)", urls[i])
nb = nb.group()
m2 = re.search(r"-([^-]*)", nb)
m2 = m2.group()
m2 = str(m2)
subs = m2.split("-")[1]
idx0 = urls[i].index("python")
nm = urls[i][idx0 + 7 : idx0 + 9]
nm = nm[0] + "." + nm[1]
idx = urls[i].index(".zip")
nbits = urls[i][idx - 2 : idx]
if branch == "v0.6.0":
result = re.search("python(.*)-v0.6.0", urls[i])
if branch == "master":
result = re.search("python(.*)-master", urls[i])
other = result.group(1)
nm = nm + " "
nm = os_version(nbits)
nm = nm
nm += get_os(urls[i], nm)
names.append(
"IfcBlender for python" + " " + other[1] + "." + other[2] + " " + nm
)
if product == "IfcConvert":
nm = ""
idx = urls[i].index(".zip")
nbits = urls[i][idx - 2 : idx]
nm = os_version(nbits)
nm += get_os(urls[i], nm)
names.append("IfcConvert" + " " + nm)
if product == "ifcopenshell-python":
if branch == "v0.6.0":
nb = re.search(r"(python-(.*)-v0\.6\.0)", urls[i])
nb = nb.group()
if branch == "master":
nb = re.search(r"(python-(.*)-master)", urls[i])
nb = nb.group()
m2 = re.search(r"-([^-]*)", nb)
m2 = m2.group()
m2 = str(m2)
subs = m2.split("-")[1]
nm = subs[0] + "." + subs[1]
idx = urls[i].index(".zip")
nbits = urls[i][idx - 2 : idx]
if branch == "v0.6.0":
result = re.search("python(.*)-v0.6.0", urls[i])
if branch == "master":
result = re.search("python(.*)-master", urls[i])
other = result.group(1)
nm = nm + " "
nm = os_version(nbits)
nm += get_os(urls[i], nm)
if urls[i][67] == "u":
# handle the python X.Yu case.
names.append(
"IfcOpenShell-python for python"
+ " "
+ other[1]
+ "."
+ other[2]
+ "u"
+ nm
)
else:
names.append(
"IfcOpenShell-python for python"
+ " "
+ other[1]
+ "."
+ other[2]
+ nm
)
for i in range(len(urls)):
t = (urls[i], names[i])
if "linux" in urls[i]:
final_dict["Linux"].append(t)
if "os" in urls[i]:
final_dict["OSX"].append(t)
if "win" in urls[i]:
final_dict["Windows"].append(t)
for k, v in final_dict.items():
final_dict[k] = [t for t in (set(tuple(i) for i in v))]
final_dict[k] = sorted(final_dict[k], key=lambda x: x[1])
return final_dict
except Exception as e:
import traceback
traceback.print_exc()
return {"Windows": [], "OSX": [], "Linux": []}
if __name__ == "__main__":
print("Use this module to construct the IfcOpenShell builds")