]> git.pld-linux.org Git - projects/pld-builder.new.git/blob - PLD_Builder/build.py
- different approach: skip command into shell commands
[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
20 def run_command(batch):
21     # we want to keep "skip" in queue.html
22     command = batch.command
23
24     # rewrite special "skip:BUILD_ID into touch
25     if command[:5] == "skip:":
26         c = "set -x; echo SKIPME; echo SKIPME >&2;"
27         for id in command[5:].split(','):
28             if os.path.isdir(path.srpms_dir + '/' + id):
29                 c = c + "echo skip:%s;\n" % (id)
30                 c = c + "touch %s/%s;\n" % (path.srpms_dir, id)
31             else:
32                 c = c + "echo %s is not valid build-id;\n" % (id)
33         command = c
34
35     if "no-chroot" in batch.command_flags:
36         c = "%s >> %s 2>&1" % (command, batch.logfile)
37         f = os.popen(c)
38         for l in f.xreadlines():
39             pass
40         r = f.close()
41         if r == None:
42             return 0
43         else:
44             return r
45     else:
46         user = "root"
47         if "as-builder" in batch.command_flags:
48             user = "builder"
49         return chroot.run(command, logfile = batch.logfile, user = user)
50
51 def build_all(r, build_fnc):
52     status.email = r.requester_email
53     notify.begin(r)
54     tmp = path.build_dir + '/' + util.uuid() + "/"
55     r.tmp_dir = tmp
56     os.mkdir(tmp)
57     atexit.register(util.clean_tmp, tmp)
58
59     log.notice("started processing %s" % r.id)
60     r.chroot_files = []
61     r.some_ok = 0
62     for batch in r.batches:
63         can_build = 1
64         failed_dep = ""
65         for dep in batch.depends_on:
66             if dep.build_failed:
67                 can_build = 0
68                 failed_dep = dep.spec
69         
70         if batch.is_command() and can_build:
71             batch.logfile = tmp + "command"
72             if config.builder in batch.builders:
73                 log.notice("running %s" % batch.command)
74                 stopwatch.start()
75                 batch.build_failed = run_command(batch)
76                 if batch.build_failed:
77                     log.notice("running %s FAILED" % batch.command)
78                     notify.add_batch(batch, "FAIL")
79                 else:
80                     r.some_ok = 1
81                     log.notice("running %s OK" % batch.command)
82                     notify.add_batch(batch, "OK")
83                 batch.build_time = stopwatch.stop()
84                 report.add_pld_builder_info(batch)
85                 buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
86             else:
87                 log.notice("not running command, not for me.")
88                 batch.build_failed = 0
89                 batch.log_line("queued command %s for other builders" % batch.command)
90                 r.some_ok = 1
91                 buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
92         elif can_build:
93             log.notice("building %s" % batch.spec)
94             stopwatch.start()
95             batch.logfile = tmp + batch.spec + ".log"
96             batch.gb_id=r.id
97             batch.requester=r.requester
98             batch.requester_email=r.requester_email
99             batch.build_failed = build_fnc(r, batch)
100             if batch.build_failed:
101                 log.notice("building %s FAILED (%s)" % (batch.spec, batch.build_failed))
102                 notify.add_batch(batch, batch.build_failed)
103             else:
104                 r.some_ok = 1
105                 log.notice("building %s OK" % (batch.spec))
106                 notify.add_batch(batch, "OK")
107             batch.build_time = stopwatch.stop()
108             report.add_pld_builder_info(batch)
109             buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
110         else:
111             batch.build_failed = 1
112             batch.skip_reason = "SKIPED [%s failed]" % failed_dep
113             batch.logfile = None
114             batch.build_time = ""
115             log.notice("building %s %s" % (batch.spec, batch.skip_reason))
116             notify.add_batch(batch, "SKIP")
117             
118     buildlogs.flush()
119     chroot.run("rm -f %s" % string.join(r.chroot_files))
This page took 0.070575 seconds and 4 git commands to generate.