]> TLD Linux GIT Repositories - TLD.git/blob - pld-builder.new/PLD_Builder/buildlogs.py
0bcd530b0e505413005c3c4dc7e36c9c22662a5a
[TLD.git] / pld-builder.new / PLD_Builder / buildlogs.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import path
4 import time
5 import os
6 import re
7 import log
8
9 from config import config
10 import util
11
12 class Buildlogs_Queue:
13     def __init__(self):
14         self.queue = []
15         self.some_failed = 0
16         self.requester_email = None
17
18     def init(self, g):
19         self.requester_email = g.requester_email
20
21     def add(self, logfile, failed, id):
22         # if /dev/null, don't even bother to store it
23         if config.buildlogs_url == "/dev/null":
24             return
25         blogfile = os.path.basename(logfile)
26         name = re.sub(r"\.spec\.log", "", blogfile) + "," + id + ".bz2"
27         ret = os.system("bzip2 --best --force < %s > %s" \
28                     % (logfile, path.buildlogs_queue_dir + '/' + config.builder + '.' + id + '.' + blogfile))
29         if ret:
30             log.error("bzip2 compression of %s failed; does bzip2 binary exist?" % (logfile))
31
32         if failed: s = "FAIL"
33         else: s = "OK"
34         f = open(path.buildlogs_queue_dir + '/' + config.builder + '.' + id + '.' + blogfile + ".info", "w")
35         f.write("Status: %s\nEND\n" % s)
36         f.close()
37
38         self.queue.append({'name': name, 'id': config.builder + '.' + id + '.' + blogfile, 'failed': failed})
39
40     def flush(self):
41         def desc(l):
42             return """Target: %s/%s
43 Builder: %s
44 Time: %d
45 Type: buildlog
46 Requester: %s
47 END
48 """ % (config.buildlogs_url, l['name'], config.builder, time.time(), self.requester_email)
49
50         q = self.queue[:]
51         for l in q:
52             f = open(path.buildlogs_queue_dir + '/' + l['id'] + ".desc.tmp", "w")
53             f.write(desc(l))
54             f.close()
55             os.rename(path.buildlogs_queue_dir + '/' + l['id'] + ".desc.tmp", path.buildlogs_queue_dir + '/' + l['id'] + ".desc")
56             self.queue.remove(l)
57
58 queue = Buildlogs_Queue()
59
60 def init(r):
61     queue.init(r)
62
63 def add(logfile, failed, id):
64     "Add new buildlog with specified status."
65     queue.add(logfile, failed, id)
66
67 def flush():
68     "Send buildlogs to server."
69     queue.flush()