-
Notifications
You must be signed in to change notification settings - Fork 11
/
BBSreportutils.py
449 lines (398 loc) · 15.9 KB
/
BBSreportutils.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
##############################################################################
###
### This file is part of the BBS software (Bioconductor Build System).
###
### Author: Hervé Pagès <[email protected]>
### Last modification: Jul 6, 2021
###
import sys
import os
import string
import urllib.request
import bbs.parse
import BBSutils
import BBSvars
##############################################################################
### write_htaccess_file()
##############################################################################
### Placing this .haccess file in the top-level folder of the build report
### will help the various text files (i.e. non-HTML) included in the report
### get properly displayed in a browser. For example, without this .haccess
### file, things like R's beloved fancy quotes that are commonly found in
### "raw result" files will look like garbbage (e.g. ‘Rhdf5lib’) in most
### browsers.
### Note that using the UTF-8 encoding solves most displaying issues but not
### all of them. For example it won't help with charaters from exotic encodings
### that are sometimes found in the meat-index.dcf file (in the Maintainer
### field of some packages).
### Finally note that using this .htaccess file only solves a cosmetic issue
### (i.e. it only affects how the text files included in the report get
### displayed in a browser). Most importantly, these text files are what they
### are and tools like wget or curl will download them as-is, regardless of
### what their original encoding is and regardless of what encoding is
### specified in the .htaccess file.
def write_htaccess_file():
out = open('.htaccess', 'w')
out.write('AddCharset UTF-8 .dcf .txt .TXT .log\n')
out.close()
return
##############################################################################
###
### The NODES db (in memory)
###
##############################################################################
class Node:
def __init__(self, hostname, node_id, os_html, arch, platform, buildbin, pkgs):
self.hostname = hostname
self.node_id = node_id
self.os_html = os_html
self.arch = arch
self.platform = platform
self.buildbin = buildbin # boolean (or None if foreign node)
self.pkgs = pkgs # list of pkg names
### A list of Node objects
NODES = []
def fancyname_has_suffix(fancyname, suffix):
ns = fancyname.split(":")
if len(ns) == 1:
return False
if len(ns) > 2:
sys.exit("Invalid node specification: %s => EXIT." % fancyname)
return ns[1] == suffix
def set_NODES(fancynames_in_one_string):
fancynames = fancynames_in_one_string.split(' ')
for fancyname in fancynames:
if fancyname == "":
continue
node_id = fancyname.split(":")[0]
hostname = node_id.split("-")[0]
os_html = BBSutils.getNodeSpec(hostname, 'OS').replace(' ', ' ')
arch = BBSutils.getNodeSpec(hostname, 'Arch')
platform = BBSutils.getNodeSpec(hostname, 'Platform')
foreign = fancyname_has_suffix(fancyname, "foreign")
if foreign:
buildbin = pkgs = None
else:
buildbin = fancyname_has_suffix(fancyname, "bin")
pkgType = BBSutils.getNodeSpec(hostname, 'pkgType')
pkgs = bbs.parse.get_meat_packages_for_node(
BBSutils.meat_index_file,
hostname, arch, pkgType)
node = Node(hostname, node_id, os_html, arch, platform, buildbin, pkgs)
NODES.append(node)
if len(NODES) == 0:
sys.exit("nothing to report (no nodes) => EXIT.")
return
def is_doing_buildbin(node):
return node.buildbin == True # node.buildbin can be None if foreign node
def supported_pkgs(node):
return node.pkgs
def is_supported(pkg, node):
return pkg in supported_pkgs(node)
def supported_nodes(pkg):
nodes = []
for node in NODES:
if node.buildbin == None: # foreign node
continue
if is_supported(pkg, node):
nodes.append(node)
return nodes
##############################################################################
###
### make_report_title()
### stages_to_display()
###
##############################################################################
def make_report_title(report_nodes):
buildtype = BBSvars.buildtype
if buildtype == "workflows":
title = "Workflows build"
elif buildtype == "books":
title = "Books build"
elif buildtype == "bioc-longtests":
title = "Long Tests"
elif buildtype == "bioc-mac-arm64":
title = "Mac ARM64 build"
elif buildtype == "bioc-rapid":
title = 'Rapid builds (Linux only) of a subset of BioC 3.21<BR>' + \
'Report updated every 6 hours'
return title
elif buildtype == "bioc-testing":
title = '"Blame Jeroen" build/check'
else:
nnodes = 0
for node in report_nodes.split(' '):
if node == "":
continue
nnodes += 1
if nnodes != 1:
title = "Multiple platform build/check"
else:
title = "Build/check"
title += " report for "
if buildtype == "cran":
title += "CRAN"
else:
title += "BioC %s" % BBSvars.bioc_version
if buildtype == "data-annotation":
title += " annotations"
elif buildtype == "data-experiment":
title += " experimental data"
return title
def stage_label(stage):
stage2label = {
'install': "INSTALL",
'buildsrc': "BUILD",
'checksrc': "CHECK",
'buildbin': "BUILD BIN"
}
return stage2label[stage]
## Stages to display on the report (as columns in HTML table) for the given
## buildtype. Should be a subset of the stages that were run because we
## obviously can't display the results for stages that we didn't run.
## However we don't necessarily want to display the results for all the
## stages that we ran. For example, for the "bioc-longtests" buildtype
## we run 'buildsrc' (STAGE3) and 'checksrc' (STAGE4) but we only display
## the results of 'checksrc' (CHECK column on the report).
def stages_to_display(buildtype):
if buildtype in ["data-annotation", "data-experiment", "books", "bioc-rapid"]:
return ['install', 'buildsrc', 'checksrc']
if buildtype == "workflows":
return ['install', 'buildsrc']
if buildtype == "bioc-longtests":
return ['checksrc'] # we run 'buildsrc' but don't display it
return ['install', 'buildsrc', 'checksrc', 'buildbin']
### Whether to display the package propagation status led or not for the
### given buildtype.
def display_propagation_status(buildtype):
return buildtype not in ["bioc-longtests", "bioc-rapid", "bioc-testing", "cran"]
def ncol_to_display(buildtype):
return len(stages_to_display(buildtype)) + \
display_propagation_status(buildtype)
##############################################################################
BUILD_STATUS_DB_file = 'BUILD_STATUS_DB.txt'
PROPAGATION_STATUS_DB_file = 'PROPAGATION_STATUS_DB.txt'
##############################################################################
def map_package_type_to_outgoing_node(package_type):
map = {}
rawmap = os.getenv("BBS_OUTGOING_MAP")
segs = rawmap.split(" ")
for seg in segs:
key = seg.split(":")[0]
value = seg.split(":")[1].split("/")[0]
map[key] = value
return map[package_type]
def map_outgoing_node_to_package_type(node):
map = {}
rawmap = os.getenv("BBS_OUTGOING_MAP")
if rawmap == None:
return None
segs = rawmap.split(" ")
for seg in segs:
pkgtype, rest = seg.split(":")
anode = rest.split("/")[0]
map[anode] = pkgtype
if not node in map:
return None
return map[node]
def get_status(dcf, pkg, node_id, stage):
key = '%s#%s#%s' % (pkg, node_id, stage)
status = bbs.parse.get_next_DCF_val(dcf, key, full_line=True)
return status
def get_propagation_status_from_db(pkg, node_id):
try:
dcf = open(PROPAGATION_STATUS_DB_file, 'rb')
except FileNotFoundError:
return None
status = get_status(dcf, pkg,
map_outgoing_node_to_package_type(node_id),
'propagate')
dcf.close()
return status
def WReadDcfVal(rdir, file, field, full_line=False):
dcf = rdir.WOpen(file)
val = bbs.parse.get_next_DCF_val(dcf, field, full_line)
dcf.close()
return val
### Get vcs metadata for Rpacks/ or Rpacks/pkg/
def get_vcs_meta(pkg, key):
Central_rdir = BBSvars.Central_rdir
file = BBSvars.vcsmeta_file
if pkg != None:
file = "-%s.".join(file.rsplit(".", 1)) % pkg
val = WReadDcfVal(Central_rdir, file, key, True)
if val == None:
raise bbs.parse.DcfFieldNotFoundError(file, key)
return val
def get_leafreport_rel_path(pkg, node_id, stage):
return os.path.join(pkg, "%s-%s.html" % (node_id, stage))
def get_leafreport_rel_url(pkg, node_id, stage):
return "%s/%s-%s.html" % (pkg, node_id, stage)
##############################################################################
###
### import_BUILD_STATUS_DB()
### get_pkg_status()
###
##############################################################################
def _get_pkg_status_from_BUILD_STATUS_DB(BUILD_STATUS_DB, pkg, node_id, stage):
key = '%s#%s#%s' % (pkg, node_id, stage)
return BUILD_STATUS_DB[key]
_build_status_db = {}
def _set_pkg_status(pkg, node_id, stage, status):
if pkg not in _build_status_db:
_build_status_db[pkg] = {}
if node_id not in _build_status_db[pkg]:
_build_status_db[pkg][node_id] = {}
_build_status_db[pkg][node_id][stage] = status
return
def _zero_quickstats():
quickstats = {}
for node in NODES:
if node.buildbin == None: # foreign node
continue
quickstats[node.node_id] = { 'install': (0, 0, 0, 0, 0), \
'buildsrc': (0, 0, 0, 0, 0), \
'checksrc': (0, 0, 0, 0, 0), \
'buildbin': (0, 0, 0, 0, 0) }
return quickstats
def _update_quickstats(quickstats, node_id, stage, status):
x = quickstats[node_id][stage]
x0 = x[0]
x1 = x[1]
x2 = x[2]
x3 = x[3]
x4 = x[4]
if status == "TIMEOUT":
x0 += 1
if status == "ERROR":
x1 += 1
if status == "WARNINGS":
x2 += 1
if status == "OK":
x3 += 1
if status == "NotNeeded":
x4 += 1
quickstats[node_id][stage] = (x0, x1, x2, x3, x4)
return
def import_BUILD_STATUS_DB(allpkgs):
BUILD_STATUS_DB = bbs.parse.parse_DCF(BUILD_STATUS_DB_file,
merge_records=True)
allpkgs_quickstats = _zero_quickstats()
for pkg in allpkgs:
for node in supported_nodes(pkg):
# INSTALL status
if BBSvars.buildtype != "bioc-longtests":
stage = 'install'
status = _get_pkg_status_from_BUILD_STATUS_DB(
BUILD_STATUS_DB,
pkg, node.node_id, stage)
_set_pkg_status(pkg, node.node_id, stage, status)
_update_quickstats(allpkgs_quickstats,
node.node_id, stage, status)
# BUILD status
stage = 'buildsrc'
status = _get_pkg_status_from_BUILD_STATUS_DB(
BUILD_STATUS_DB,
pkg, node.node_id, stage)
_set_pkg_status(pkg, node.node_id, stage, status)
_update_quickstats(allpkgs_quickstats, node.node_id, stage, status)
skipped_is_OK = status in ["TIMEOUT", "ERROR"]
# CHECK status
if BBSvars.buildtype != "workflows":
stage = 'checksrc'
if skipped_is_OK:
status = "skipped"
else:
status = _get_pkg_status_from_BUILD_STATUS_DB(
BUILD_STATUS_DB,
pkg, node.node_id, stage)
_set_pkg_status(pkg, node.node_id, stage, status)
_update_quickstats(allpkgs_quickstats,
node.node_id, stage, status)
# BUILD BIN status
if is_doing_buildbin(node):
stage = 'buildbin'
if skipped_is_OK:
status = "skipped"
else:
status = _get_pkg_status_from_BUILD_STATUS_DB(
BUILD_STATUS_DB,
pkg, node.node_id, stage)
_set_pkg_status(pkg, node.node_id, stage, status)
_update_quickstats(allpkgs_quickstats,
node.node_id, stage, status)
return allpkgs_quickstats
def get_pkg_status(pkg, node_id, stage):
if len(_build_status_db) == 0:
sys.exit("You must import package statuses with " + \
"BBSreportutils.import_BUILD_STATUS_DB() before " + \
"using BBSreportutils.get_pkg_status() => EXIT.")
return _build_status_db[pkg][node_id][stage]
def get_distinct_pkg_statuses(pkg, nodes=None):
if nodes == None:
nodes = NODES
statuses = []
for node in nodes:
if node.buildbin == None: # foreign node
continue
if not is_supported(pkg, node):
continue
stages = stages_to_display(BBSvars.buildtype)
if 'buildbin' in stages and not is_doing_buildbin(node):
stages.remove('buildbin')
for stage in stages:
status = get_pkg_status(pkg, node.node_id, stage)
if status != "skipped" and status not in statuses:
statuses.append(status)
return statuses
##############################################################################
### Used in mini reports for direct reverse deps
##############################################################################
### Only report reverse deps that are **within** 'pkgs'.
def get_inner_reverse_deps(pkgs, pkg_dep_graph):
inner_rev_deps = {}
for pkg in pkgs:
inner_rev_deps[pkg] = []
for pkg in pkg_dep_graph.keys():
if pkg not in pkgs:
continue
pkg_direct_deps = pkg_dep_graph[pkg]
for pkg_direct_dep in pkg_direct_deps:
if pkg_direct_dep not in pkgs or \
pkg in inner_rev_deps[pkg_direct_dep]:
continue
inner_rev_deps[pkg_direct_dep].append(pkg)
for pkg in pkgs:
inner_rev_deps[pkg].sort(key=str.lower)
return inner_rev_deps
def compute_quickstats(pkgs):
quickstats = _zero_quickstats()
for pkg in pkgs:
for node in supported_nodes(pkg):
# INSTALL status
if BBSvars.buildtype != "bioc-longtests":
stage = 'install'
status = get_pkg_status(pkg, node.node_id, stage)
_update_quickstats(quickstats, node.node_id, stage, status)
# BUILD status
stage = 'buildsrc'
status = get_pkg_status(pkg, node.node_id, stage)
_update_quickstats(quickstats, node.node_id, stage, status)
skipped_is_OK = status in ["TIMEOUT", "ERROR"]
# CHECK status
if BBSvars.buildtype != "workflows":
stage = 'checksrc'
if skipped_is_OK:
status = "skipped"
else:
status = get_pkg_status(pkg, node.node_id, stage)
_update_quickstats(quickstats, node.node_id, stage, status)
# BUILD BIN status
if is_doing_buildbin(node):
stage = 'buildbin'
if skipped_is_OK:
status = "skipped"
else:
status = get_pkg_status(pkg, node.node_id, stage)
_update_quickstats(quickstats, node.node_id, stage, status)
return quickstats