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