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
|
#!/usr/bin/python
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
from udd import icommon
def write_email(failures):
text = ""
for package, reason, when_failed in failures:
if reason == icommon.running_sentinel:
continue
text += "\n\n%s failed at %s due to:\n%s\n" % (
package, when_failed, reason.encode("ascii", "replace"))
return text
def only_main(failures):
db = icommon.PackageDatabase(icommon.sqlite_package_file)
main_packages = db.list_packages_in_main()
filtered = []
for failure in failures:
package = failure[0]
if package in main_packages:
filtered.append(failure)
return filtered
def email_failures():
db = icommon.StatusDatabase(icommon.sqlite_file)
failures = db.unemailed_failures()
failures = only_main(failures)
if failures:
content = write_email(failures)
print content
db.set_failures_emailed(failures)
def main():
lock = icommon.lock_email_failures()
if lock is None:
print "Another instance of email_failures is already running."
sys.exit(0)
try:
email_failures()
finally:
lock.close()
if __name__ == '__main__':
main()
|