]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/build.py
- use request id
[projects/pld-builder.new.git] / PLD_Builder / build.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import string
4 import os
5 import atexit
6
7 import notify
8 import path
9 import util
10 import chroot
11 import stopwatch
12 import report
13 import log
14 import buildlogs
15 import status
16 from config import config, init_conf
17
18
19 def run_command(batch):
20     if "no-chroot" in batch.command_flags:
21         c = "%s >> %s 2>&1" % (batch.command, batch.logfile)
22         f = os.popen(c)
23         for l in f.xreadlines():
24             pass
25         r = f.close()
26         if r == None:
27             return 0
28         else:
29             return r
30     else:
31         user = "root"
32         if "as-builder" in batch.command_flags:
33             user = "builder"
34         return chroot.run(batch.command, logfile = batch.logfile, user = user)
35
36 def build_all(r, build_fnc):
37     status.email = r.requester_email
38     notify.begin(r)
39     tmp = path.build_dir + util.uuid() + "/"
40     r.tmp_dir = tmp
41     os.mkdir(tmp)
42     atexit.register(util.clean_tmp, tmp)
43
44     log.notice("started processing %s" % r.id)
45     r.chroot_files = []
46     r.some_ok = 0
47     for batch in r.batches:
48         can_build = 1
49         failed_dep = ""
50         for dep in batch.depends_on:
51             if dep.build_failed:
52                 can_build = 0
53                 failed_dep = dep.spec
54         
55         if batch.is_command() and can_build:
56             batch.logfile = tmp + "command"
57             if config.builder in batch.builders:
58                 log.notice("running %s" % batch.command)
59                 stopwatch.start()
60                 batch.build_failed = run_command(batch)
61                 if batch.build_failed:
62                     log.notice("running %s FAILED" % batch.command)
63                     notify.add_batch(batch, "FAIL")
64                 else:
65                     r.some_ok = 1
66                     log.notice("running %s OK" % batch.command)
67                     notify.add_batch(batch, "OK")
68                 batch.build_time = stopwatch.stop()
69                 report.add_pld_builder_info(batch)
70                 buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
71             else:
72                 log.notice("not running command, not for me.")
73                 batch.build_failed = 0
74                 batch.log_line("queued command %s for other builders" % batch.command)
75                 r.some_ok = 1
76                 buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
77         elif can_build:
78             log.notice("building %s" % batch.spec)
79             stopwatch.start()
80             batch.logfile = tmp + batch.spec + ".log"
81             batch.gb_id=r.id
82             batch.requester=r.requester
83             batch.requester_email=r.requester_email
84             batch.build_failed = build_fnc(r, batch)
85             if batch.build_failed:
86                 log.notice("building %s FAILED" % batch.spec)
87                 notify.add_batch(batch, "FAIL")
88             else:
89                 r.some_ok = 1
90                 log.notice("building %s OK" % batch.spec)
91                 notify.add_batch(batch, "OK")
92             batch.build_time = stopwatch.stop()
93             report.add_pld_builder_info(batch)
94             buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
95         else:
96             batch.build_failed = 1
97             batch.skip_reason = "SKIPED [%s failed]" % failed_dep
98             batch.logfile = None
99             batch.build_time = ""
100             log.notice("building %s %s" % (batch.spec, batch.skip_reason))
101             notify.add_batch(batch, "SKIP")
102             
103     buildlogs.flush()
104     chroot.run("rm -f %s" % string.join(r.chroot_files))
This page took 0.036491 seconds and 4 git commands to generate.