1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
29 from bqueue import B_Queue
30 from config import config, init_conf
34 if r1.kind != 'group' or r2.kind != 'group':
35 raise Exception("non-group requests")
36 pri_diff = util.cmp(r1.priority, r2.priority)
38 return util.cmp(r1.time, r2.time)
41 q.requests.sort(key=util.cmp_to_key(mycmp))
43 q.requests = q.requests[1:]
46 def store_binary_request(r):
49 if not b.build_failed: new_b.append(b)
53 # store new queue and max_req_no for binary builders
54 num = int(open(path.max_req_no_file, "r").read().strip()) + 1
57 q = B_Queue(path.req_queue_file)
62 q.dump(path.queue_stats_file)
63 q.dump_html(path.queue_html_stats_file)
64 q.write_signed(path.req_queue_signed_file)
67 (fdno, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(path.max_req_no_file))
68 cnt_f = os.fdopen(fdno, "w")
70 cnt_f.write("%d\n" % num)
72 os.fsync(cnt_f.fileno())
74 os.chmod(tmpfname, 0o0644)
75 os.rename(tmpfname, path.max_req_no_file)
77 def transfer_file(r, b):
78 local = path.srpms_dir + '/' + r.id + "/" + b.src_rpm
80 # export files from chroot
81 chroot.cp(f, outfile = local, rm = True)
82 os.chmod(local, 0o0644)
85 if config.gen_upinfo and 'test-build' not in r.flags:
86 fname = path.srpms_dir + '/' + r.id + "/" + b.src_rpm + ".uploadinfo"
88 f.write("info:build:%s:requester:%s\ninfo:build:%s:requester_email:%s\nfile:SRPMS:%s\nEND\n" % (b.gb_id, b.requester, b.gb_id, b.requester_email, b.src_rpm))
90 ftp.add(fname, "uploadinfo")
93 if len(b.spec) <= len('.spec'):
94 # should not really get here
95 util.append_to(b.logfile, "error: No .spec given but build src.rpm wanted")
98 status.push("building %s" % b.spec)
99 # messagebus.notify(topic="build_srpm.start", spec=b.spec, flags=r.flags, batch=b, request=r)
102 builder_opts = "-nu -nm --nodeps --http --define \'_tld_builder 1\'"
103 cmd = ("cd rpm/packages; nice -n %s ./builder %s -bs %s -r %s %s %s %s 2>&1" %
104 (config.nice, builder_opts, b.bconds_string(), b.branch,
105 b.kernel_string(), b.defines_string(), b.spec))
106 util.append_to(b.logfile, "request from: %s" % r.requester)
107 util.append_to(b.logfile, "started at: %s" % time.asctime())
108 util.append_to(b.logfile, "building SRPM using: %s\n" % cmd)
109 res = chroot.run(cmd, logfile = b.logfile)
110 util.append_to(b.logfile, "exit status %d" % res)
111 files = util.collect_files(b.logfile)
114 util.append_to(b.logfile, "error: More than one file produced: %s" % files)
115 res = "FAIL_TOOMANYFILES"
116 last = files[len(files) - 1]
117 b.src_rpm_file = last
118 b.src_rpm = os.path.basename(last)
119 r.chroot_files.extend(files)
121 util.append_to(b.logfile, "error: No files produced.")
123 if res == 0 and not "test-build" in r.flags:
124 util.append_to(b.logfile, "Writing package revision")
125 res = chroot.run("cd rpm/packages; ./builder -bs %s -r %s --pkgrev %s %s" % \
126 (b.bconds_string(), b.branch, b.defines_string(), b.spec), logfile = b.logfile)
130 packagename = b.spec[:-5]
131 packagedir = "rpm/packages/%s" % packagename
132 chroot.run("rpm/packages/builder -m %s" % \
133 (b.spec,), logfile = b.logfile)
134 chroot.run("rm -rf %s" % packagedir, logfile = b.logfile)
140 # messagebus.notify(topic="build_srpm.finish", spec=b.spec)
143 def handle_request(r):
144 os.mkdir(path.srpms_dir + '/' + r.id)
145 os.chmod(path.srpms_dir + '/' + r.id, 0o0755)
148 build.build_all(r, build_srpm)
149 report.send_report(r, is_src = True)
150 report.send_cia_report(r, is_src = True)
151 store_binary_request(r)
157 if lock("building-srpm", non_block = 1) == None:
160 status.push("srpm: processing queue")
161 q = B_Queue(path.queue_file)
174 status.push("srpm: handling request from %s" % r.requester)
178 if __name__ == '__main__':