def command_sh(cmd):
return "sudo chroot %s /bin/sh -c \"export LC_ALL=C; %s\"" % (config.chroot, quote(cmd))
-def popen(cmd, user = None):
+def popen(cmd, user = "builder"):
f = os.popen(command(cmd, user))
return f
-def run(cmd, user = None, logfile = None)
+def run(cmd, user = "builder", logfile = None):
c = command(cmd, user)
if logfile != None:
c = "%s >> %s 2>&1" % (c, logfile)
r = f.close()
if r == None:
return 0
- else
+ else:
return r
import string
import time
import os
+import os.path
import StringIO
import sys
+import re
import gpg
import request
from lock import lock
from bqueue import B_Queue
from config import config, init_conf
-
import chroot
+import buildlogs
def pick_request(q):
def mycmp(r1, r2):
return cmp(r1.time, r2.time)
else:
return pri_diff
- q.batches.sort(mycmp)
- ret = q.batches[0]
- q.batches = q.batches[1:]
+ q.requests.sort(mycmp)
+ ret = q.requests[0]
+ q.requests = q.requests[1:]
return ret
def collect_files(log):
files.append(m.group(1))
return files
-def append_to(log, msg)
+def append_to(log, msg):
f = open(log, "a")
f.write("%s\n" % msg)
f.close()
b.src_rpm = ""
builder_opts = "-nu --clean --nodeps"
cmd = "cd rpm/SPECS; ./builder %s -bs %s -r %s %s 2>&1" % \
- (build_opts, b.bconds_string(), b.branch, b.spec)
+ (builder_opts, b.bconds_string(), b.branch, b.spec)
spec_log = tmp + b.spec + ".log"
append_to(spec_log, "Building SRPM using: %s\n" % cmd)
res = chroot.run(cmd, logfile = spec_log)
if len(files) > 1:
append_to(spec_log, "error: More then one file produced: %s" % files)
res = 1
- b.src_rpm = files[len(files) - 1]
+ last = files[len(files) - 1]
+ b.src_rpm_file = last
+ b.src_rpm = os.path.basename(last)
all_files.extend(files)
else:
append_to(spec_log, "error: No files produced.")
buildlogs.add(logfile = spec_log, failed = res)
return res
- tmp = spool_dir + r.id + "/"
- mkdir(tmp)
+ tmp = path.spool_dir + r.id + "/"
+ os.mkdir(tmp)
user = acl.user(r.requester)
log.notice("started processing %s" % r.id)
all_files = []
log.notice("building %s failed" % batch.spec)
chroot.run("rm -f %s" % string.join(all_files))
m = user.message_to()
- m.set_headers(subject = "SRPMS: %s failed" % r.spec)
- m.write("Building SRPM failed for %s.\nAttached log:\n" % r.spec)
- m.append_log(tmp + b.spec + ".log")
+ m.set_headers(subject = "SRPMS: %s failed" % batch.spec)
+ # FIXME: write about other specs from group
+ m.write("Building SRPM failed for %s.\nAttached log:\n" % batch.spec)
+ m.append_log(tmp + batch.spec + ".log")
m.send()
buildlogs.flush()
clean_tmp(tmp)
return
+ log.notice("building %s finished" % batch.spec)
os.mkdir(path.srpms_dir + r.id)
for batch in r.batches:
# export files from chroot
local = path.srpms_dir + r.id + "/" + batch.src_rpm
+ f = batch.src_rpm_file
chroot.run("cat %s; rm -f %s" % (f, f), logfile = local)
# FIXME: copy files to ftp
# store new queue and counter for binary builders
- cnt_f = open(counter_file, "r+")
+ cnt_f = open(path.counter_file, "r+")
num = int(string.strip(cnt_f.read()))
r.no = num
q = B_Queue(path.req_queue_file)
q.write()
q.unlock()
q.write_signed(path.req_queue_signed_file)
- num++
+ num += 1
cnt_f.seek(0)
cnt_f.write("%d\n" % num)
cnt_f.close()
+ # FIXME: send notification?
def main():
init_conf("src")
q = B_Queue(path.queue_file)
if not q.lock(1): return
q.read()
- if q.batches == []: return
+ if q.requests == []: return
r = pick_request(q)
q.write()
q.unlock()