]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/report.py
- argh
[projects/pld-builder.new.git] / PLD_Builder / report.py
1 import string
2
3 import ftp
4 import stopwatch
5 import mailer
6 from config import config
7
8 def unpackaged_files(b):
9   msg = "warning: Installed (but unpackaged) file(s) found:\n"
10   f = open(b.logfile)
11   copy_mode = 0
12   out = []
13   for l in f.xreadlines():
14     if l == msg:
15       copy_mode = 1
16       out.append(l)
17     elif copy_mode:
18       if l[0] != ' ':
19         copy_mode = 0
20       else:
21         out.append(l)
22   return out
23
24 def add_pld_builder_info(b):
25   l = open(b.logfile, "a")
26   l.write("Begin-PLD-Builder-Info\n")
27   l.write("Build-Time: %s\n\n" % b.build_time)
28   st = ftp.status()
29   if st != "":
30     l.write("Files queued for ftp:\n%s\n" % st)
31   ftp.clear_status()
32   l.writelines(unpackaged_files(b))
33   l.write("End-PLD-Builder-Info\n")
34
35 def info_from_log(b, target):
36   beg = "Begin-PLD-Builder-Info\n"
37   end = "End-PLD-Builder-Info\n"
38   f = open(b.logfile)
39   copy_mode = 0
40   need_header = 1
41   for l in f.xreadlines():
42     if l == beg:
43       if need_header:
44         need_header = 0
45         target.write("\n--- %s:%s:\n" % (b.spec, b.branch))
46       copy_mode = 1
47     elif copy_mode:
48       if l == end:
49         copy_mode = 0
50       else:
51         target.write(l)
52   
53 def send_report(r, is_src = False):
54   s_failed = ' '.join([b.spec for b in r.batches if b.build_failed])
55   s_ok = ' '.join([b.spec for b in r.batches if not b.build_failed])
56
57   if s_failed: s_failed = "ERRORS: %s" % s_failed
58   if s_ok: s_ok = "OK: %s" % s_ok
59
60   subject = ' '.join((s_failed, s_ok))
61   
62   m = mailer.Message()
63   m.set_headers(to = r.requester_email,
64                 cc = config.builder_list,
65                 subject = subject[0:100])
66   if is_src:
67     m.set_header("Message-ID", "<%s@pld.src.builder>" % r.id)
68   else:
69     m.set_header("References", "<%s@pld.src.builder>" % r.id)
70     m.set_header("In-Reply-To", "<%s@pld.src.builder>" % r.id)
71
72   for b in r.batches:
73     if b.build_failed and b.logfile == None:
74       info = b.skip_reason
75     elif b.build_failed: 
76       info = "FAILED"
77     else: 
78       info = "OK"
79     m.write("%s (%s): %s\n" % (b.spec, b.branch, info))
80
81   for b in r.batches:
82     if b.logfile != None:
83       info_from_log(b, m)
84
85   for b in r.batches:
86     if (b.is_command () or b.build_failed) and b.logfile != None:
87       m.write("\n\n*** buildlog for %s\n" % b.spec)
88       m.append_log(b.logfile)
89       m.write("\n\n")
90       
91   m.send()
92
93 def send_cia_report(r, is_src = False):
94
95   subject = 'DeliverXML'
96   
97   m = mailer.Message()
98   m.set_headers(to = config.bot_email,
99                 subject = subject)
100   m.set_header("Message-ID", "<%s@pld.src.builder>" % r.id)
101   m.set_header("X-mailer", "$Id$")
102   m.set_header("X-builder", "PLD")
103
104   # get header of xml message from file
105   #f = open('cia-head.xml')
106   #m.write(f.read())
107   #f.close()
108
109   # write in iteration list and status of all processed files
110   for b in r.batches:
111     # Instead of hardcoded Ac information use some config variable
112     m.write('<package name="%s" arch="%s">\n' % (b.spec, b.branch))
113     if b.build_failed:
114             m.write('<success/>\n')
115     else:
116             m.write('<failed/>\n')
117     m.write('</package>\n')
118
119   # get footer of xml message from file
120   #f.open('cia-foot.xml')
121   #m.write(f.read())
122   #f.close()
123             
124   # send the e-mail
125   m.send()
This page took 0.049257 seconds and 4 git commands to generate.