]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/mailer.py
- acl.conf for bin_builders need now only entry for src_builder
[projects/pld-builder.new.git] / PLD_Builder / mailer.py
1 import time
2 import os
3 import sys
4 import StringIO
5
6 from config import config
7 import util
8
9 class Message:
10   def __init__(self):
11     self.headers = {}
12     self.body = StringIO.StringIO()
13     self.set_std_headers()
14
15   def set_header(self, n, v):
16     self.headers[n] = v
17
18   def set_headers(self, to = None, cc = None, subject = None):
19     if to != None:
20       self.set_header("To", to)
21     if cc != None:
22       self.set_header("Cc", cc)
23     if subject != None:
24       self.set_header("Subject", subject)
25
26   def write_line(self, l):
27     self.body.write("%s\n" % l)
28
29   def write(self, s):
30     self.body.write(s)
31
32   def append_log(self, log):
33     s = os.stat(log)
34     if s.st_size > 50000:
35       # just head and tail
36       f = open(log)
37       line_cnt = 0
38       for l in f.xreadlines():
39         line_cnt += 1
40       f.seek(0)
41       line = 0
42       for l in f.xreadlines():
43         if line < 100 or line > line_cnt - 100:
44           self.body.write(l)
45         if line == line_cnt - 100:
46           self.body.write("\n\n[...]\n\n")
47         line += 1
48     else:
49       util.sendfile(open(log), self.body)
50
51   def set_std_headers(self):
52     self.headers["Date"] = time.asctime()
53     self.headers["Message-ID"] = "<pld-builder.%f.%d@%s>" \
54         % (time.time(), os.getpid(), os.uname()[1])
55     self.headers["From"] = "PLD %s builder <%s>" \
56         % (config.builder, config.email)
57     self.headers["X-PLD-Builder"] = config.builder
58
59   def write_to(self, f):
60     for k, v in self.headers.items():
61       f.write("%s: %s\n" % (k, v))
62     f.write("\n")
63     self.body.seek(0)
64     util.sendfile(self.body, f)
65
66   def send(self):
67     f = os.popen("/usr/sbin/sendmail -t", "w")
68     self.write_to(f)
69     f.close()
This page took 0.095743 seconds and 4 git commands to generate.