forked from Bioconductor/BBS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BBS-notify.py
executable file
·174 lines (147 loc) · 6.68 KB
/
BBS-notify.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
#!/usr/bin/env python3
##############################################################################
###
### This file is part of the BBS software (Bioconductor Build System).
###
### Author: Hervé Pagès <[email protected]>
### Last modification: Nov 23, 2023
###
import sys
import os
import time
import bbs.parse
import bbs.notify
import BBSutils
import BBSvars
import BBSreportutils
published_report_url = BBSutils.getenv('BBS_PUBLISHED_REPORT_URL')
from_addr = "[email protected]"
msg_head = "[This is an automatically generated email. Please don't reply.]\n"
msg_tail = "Please take the time to address this by committing and pushing\n" \
+ "changes to your package at git.bioconductor.org\n"
msg_footnote = "Notes:\n\n" \
+ " * This was the status of your package at the time this email was sent to you.\n" \
+ " Given that the online report is updated daily (in normal conditions) you\n" \
+ " could see something different when you visit the URL(s) above, especially if\n" \
+ " you do so several days after you received this email.\n\n" \
+ " * It is possible that the problems reported in this report are false positives,\n" \
+ " either because another package (from CRAN or Bioconductor) breaks your\n" \
+ " package (if yours depends on it) or because of a Build System problem.\n" \
+ " If this is the case, then you can ignore this email.\n\n" \
+ " * Please check the report again 24h after you've committed your changes to the\n" \
+ " package and make sure that all the problems have gone.\n\n" \
+ " * If you have questions about this report or need help with the\n" \
+ " maintenance of your package, please use the Bioc-devel mailing list:\n\n" \
+ " https://bioconductor.org/help/mailing-list/\n\n" \
+ " (all package maintainers are requested to subscribe to this list)\n\n" \
+ "For immediate notification of package build status, please\n" \
+ "subscribe to your package's RSS feed. Information is at:\n\n" \
+ "https://bioconductor.org/developers/rss-feeds/\n\n" \
+ "Thanks for contributing to the Bioconductor project!\n\n"
def collect_problems(pkg, node):
stage2command = {
'install': 'R CMD INSTALL',
'buildsrc': 'R CMD build',
'checksrc': 'R CMD check' if BBSvars.buildtype != 'books' else 'CHECK'
}
stages_on_report = BBSreportutils.stages_to_display(BBSvars.buildtype)
stages_to_collect = list(stage2command.keys() & stages_on_report)
problem_descs = []
for stage in stages_to_collect:
status = BBSreportutils.get_pkg_status(pkg, node.node_id, stage)
if status in ["TIMEOUT", "ERROR"]:
problem_desc = "%s for '%s' on %s" % \
(status, stage2command[stage], node.node_id)
rurl = BBSreportutils.get_leafreport_rel_url(pkg, node.node_id,
stage)
problem_desc = " o %s. See the details here:\n %s%s\n" % \
(problem_desc, published_report_url, rurl)
problem_descs.append(problem_desc)
return problem_descs
def send_notification(dcf_record):
pkg = dcf_record['Package']
package_status = dcf_record.get('PackageStatus')
if package_status == 'Deprecated':
return
maintainer_email = dcf_record['MaintainerEmail']
#print("%s %s %s %s" % (pkg, version, maintainer, maintainer_email))
#key = 'Last Changed Date'
#last_changed_date = BBSreportutils.get_vcs_meta(pkg, key)
#key = 'Last Changed Rev'
#last_changed_rev = BBSreportutils.get_vcs_meta(pkg, key)
problem_descs = []
for node in BBSreportutils.supported_nodes(pkg):
problem_descs += collect_problems(pkg, node)
if len(problem_descs) == 0:
return
report_nodes = BBSutils.getenv('BBS_REPORT_NODES')
report_title = BBSreportutils.make_report_title(report_nodes)
if maintainer_email == "[email protected]":
to_addrs = ["[email protected]"]
else:
to_addrs = [maintainer_email]
subject = "%s problems reported in the %s" % (pkg, report_title)
msg = "%s\nHi %s maintainer,\n\n" % (msg_head, pkg) \
+ "According to the %s,\n" % report_title \
+ "the %s package has the following problem(s):\n\n" % pkg \
+ "%s\n%s\n%s" % ('\n'.join(problem_descs), msg_tail, msg_footnote)
if arg1 == "":
print("###########################################################")
print("maintainer_email: %s\n" % maintainer_email)
print("subject: %s\n" % subject)
print(msg)
print()
print("BBS> Notifying maintainer(s) of %s:" % pkg)
sys.stdout.flush()
bbs.notify.sendtextmail(from_addr, to_addrs, subject, msg)
return
def send_notifications(allpkgs):
for pkg in allpkgs:
send_notification(meat_pkgs[pkg])
return
def send_BioC_notifications(allpkgs):
print("BBS> [send_BioC_notifications] BEGIN...")
send_notifications(allpkgs)
print("BBS> [send_BioC_notifications] END.")
return
def send_CRAN_notifications(allpkgs):
print("BBS> [send_CRAN_notifications] BEGIN...")
send_notifications(allpkgs)
print("BBS> [send_CRAN_notifications] END.")
return
##############################################################################
### MAIN SECTION
##############################################################################
print("BBS> [stage7] STARTING stage7 at %s..." % time.asctime())
notify_nodes = BBSutils.getenv('BBS_NOTIFY_NODES')
report_path = BBSutils.getenv('BBS_REPORT_PATH')
argc = len(sys.argv)
if argc > 1:
arg1 = sys.argv[1]
else:
arg1 = ""
if arg1 != "":
bbs.notify.mode = "do-it"
if arg1 != "do-it":
bbs.notify.redirect_to_addr = arg1
os.chdir(report_path)
BBSreportutils.set_NODES(notify_nodes)
### Compute 'meat_pkgs' (dict) and 'allpkgs' (list).
meat_index = bbs.parse.parse_DCF(BBSutils.meat_index_file)
meat_pkgs = {}
for dcf_record in meat_index:
meat_pkgs[dcf_record['Package']] = dcf_record
allpkgs = list(meat_pkgs.keys())
allpkgs.sort(key=str.lower)
print("BBS> [stage7] Import package statuses from %s ..." % \
BBSreportutils.BUILD_STATUS_DB_file, end=" ")
sys.stdout.flush()
BBSreportutils.import_BUILD_STATUS_DB(allpkgs)
print("OK")
sys.stdout.flush()
print("BBS> [stage7] Notifying package maintainers for nodes: %s" % notify_nodes)
if BBSvars.buildtype == "cran":
send_CRAN_notifications(allpkgs)
else:
send_BioC_notifications(allpkgs)
print("BBS> [stage7] DONE at %s." % time.asctime())