]> git.pld-linux.org Git - projects/pld-builder.new.git/blame - PLD_Builder/build.py
Fix iterators assumptions that are no longer valid in python3
[projects/pld-builder.new.git] / PLD_Builder / build.py
CommitLineData
dfff8bd5
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
17f23d66
MM
3import string
4import os
5import atexit
6
17f23d66
MM
7import notify
8import path
9import util
10import chroot
11import stopwatch
12import report
13import log
14import buildlogs
e2cad913 15import status
7751018d
MM
16from config import config, init_conf
17
17f23d66 18
897f56ee 19
6953ce5d 20def run_command(batch):
897f56ee
ER
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:":
93b2c381 26 c = ""
897f56ee
ER
27 for id in command[5:].split(','):
28 if os.path.isdir(path.srpms_dir + '/' + id):
29 c = c + "echo skip:%s;\n" % (id)
6923c24d 30 c = c + "touch %s/%s/skipme;\n" % (path.srpms_dir, id)
897f56ee
ER
31 else:
32 c = c + "echo %s is not valid build-id;\n" % (id)
33 command = c
34
dfff8bd5 35 if "no-chroot" in batch.command_flags:
18820286
ER
36 # TODO: the append here by shell hack should be solved in python
37 c = "(%s) >> %s 2>&1" % (command, batch.logfile)
dfff8bd5 38 f = os.popen(c)
8b63d7eb 39 for l in f:
dfff8bd5
MM
40 pass
41 r = f.close()
42 if r == None:
43 return 0
44 else:
45 return r
6953ce5d 46 else:
dfff8bd5
MM
47 user = "root"
48 if "as-builder" in batch.command_flags:
7e711a89 49 user = None
897f56ee 50 return chroot.run(command, logfile = batch.logfile, user = user)
6953ce5d 51
17f23d66 52def build_all(r, build_fnc):
dfff8bd5
MM
53 status.email = r.requester_email
54 notify.begin(r)
9be34149 55 tmp = path.build_dir + '/' + util.uuid() + "/"
dfff8bd5
MM
56 r.tmp_dir = tmp
57 os.mkdir(tmp)
58 atexit.register(util.clean_tmp, tmp)
17f23d66 59
dfff8bd5
MM
60 log.notice("started processing %s" % r.id)
61 r.chroot_files = []
62 r.some_ok = 0
63 for batch in r.batches:
64 can_build = 1
65 failed_dep = ""
66 for dep in batch.depends_on:
67 if dep.build_failed:
68 can_build = 0
69 failed_dep = dep.spec
e6376553 70
dfff8bd5
MM
71 if batch.is_command() and can_build:
72 batch.logfile = tmp + "command"
73 if config.builder in batch.builders:
74 log.notice("running %s" % batch.command)
75 stopwatch.start()
76 batch.build_failed = run_command(batch)
77 if batch.build_failed:
78 log.notice("running %s FAILED" % batch.command)
79 notify.add_batch(batch, "FAIL")
80 else:
81 r.some_ok = 1
82 log.notice("running %s OK" % batch.command)
83 notify.add_batch(batch, "OK")
84 batch.build_time = stopwatch.stop()
85 report.add_pld_builder_info(batch)
5c59479b 86 buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
dfff8bd5
MM
87 else:
88 log.notice("not running command, not for me.")
89 batch.build_failed = 0
90 batch.log_line("queued command %s for other builders" % batch.command)
91 r.some_ok = 1
5c59479b 92 buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
dfff8bd5
MM
93 elif can_build:
94 log.notice("building %s" % batch.spec)
95 stopwatch.start()
96 batch.logfile = tmp + batch.spec + ".log"
97 batch.gb_id=r.id
98 batch.requester=r.requester
99 batch.requester_email=r.requester_email
100 batch.build_failed = build_fnc(r, batch)
101 if batch.build_failed:
bf9529dc 102 log.notice("building %s FAILED (%s)" % (batch.spec, batch.build_failed))
511ece79 103 notify.add_batch(batch, batch.build_failed)
dfff8bd5
MM
104 else:
105 r.some_ok = 1
b9fffcf7
AM
106 log.notice("building %s OK" % (batch.spec))
107 notify.add_batch(batch, "OK")
dfff8bd5
MM
108 batch.build_time = stopwatch.stop()
109 report.add_pld_builder_info(batch)
5c59479b 110 buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
6953ce5d 111 else:
dfff8bd5
MM
112 batch.build_failed = 1
113 batch.skip_reason = "SKIPED [%s failed]" % failed_dep
114 batch.logfile = None
115 batch.build_time = ""
116 log.notice("building %s %s" % (batch.spec, batch.skip_reason))
117 notify.add_batch(batch, "SKIP")
e6376553 118
dfff8bd5
MM
119 buildlogs.flush()
120 chroot.run("rm -f %s" % string.join(r.chroot_files))
This page took 0.100259 seconds and 4 git commands to generate.