1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
8 from config import config
12 if s.__class__ == ''.__class__:
13 return s.decode('iso-8859-1', 'replace').encode('us-ascii', 'replace')
15 return s.encode('us-ascii', 'replace')
20 self.body = StringIO.StringIO()
21 self.set_std_headers()
23 def set_header(self, n, v):
26 def set_headers(self, to = None, cc = None, subject = None):
28 self.set_header("To", to)
30 self.set_header("Cc", cc)
32 self.set_header("Subject", subject)
34 def write_line(self, l):
35 self.body.write(recode("%s\n" % l))
38 self.body.write(recode(s))
40 def append_log(self, log):
46 for l in f.xreadlines():
50 for l in f.xreadlines():
51 if line < 100 or line > line_cnt - 100:
52 self.body.write(recode(l))
53 if line == line_cnt - 100:
54 self.body.write("\n\n[...]\n\n")
57 util.sendfile(open(log), self.body)
59 def set_std_headers(self):
60 self.headers["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())
61 self.headers["Message-ID"] = "<pld-builder.%f.%d@%s>" \
62 % (time.time(), os.getpid(), os.uname()[1])
63 self.headers["From"] = "PLD %s builder <%s>" \
64 % (config.builder, config.email)
65 self.headers["X-PLD-Builder"] = config.builder
67 def write_to(self, f):
68 for k, v in self.headers.items():
69 f.write("%s: %s\n" % (k, v))
72 util.sendfile(self.body, f)
75 send_sendmail = "/usr/sbin/sendmail -i -t -f %s" % config.admin_email
76 f = os.popen(send_sendmail, "w")