17 from bqueue import B_Queue
18 from config import config, init_conf
22 def has_new(control_url):
24 cnt_f = open(path.last_req_no_file)
25 last_count = int(string.strip(cnt_f.readline()))
27 f = urllib.urlopen(control_url + "/max_req_no")
29 if int(string.strip(f.readline())) != last_count:
34 def fetch_queue(control_url, queue_signed_by):
35 f = urllib.urlopen(control_url + "/queue.gz")
36 sio = StringIO.StringIO()
40 f = gzip.GzipFile(fileobj = sio)
41 (signers, body) = gpg.verify_sig(f)
42 u = acl.user_by_email(signers)
44 log.alert("queue.gz not signed with signature of valid user: %s" % signers)
46 if u.login != queue_signed_by:
47 log.alert("queue.gz should be signed by %s not by %s" \
48 % (queue_signed_by, u.login))
51 return request.parse_requests(body)
53 def handle_reqs(builder, reqs):
54 qpath = path.queue_file + "-" + builder
55 if not os.access(qpath, os.F_OK):
56 util.append_to(qpath, "<queue/>\n")
62 raise 'handle_reqs: fatal: huh? %s' % r.kind
65 if builder in b.builders:
68 log.notice("queued %s (%d) for %s" % (r.id, r.no, builder))
74 lock.lock("request_fetcher")
77 status.push("fetching requests")
78 if has_new(config.control_url):
79 q = fetch_queue(config.control_url, config.queue_signed_by)
87 for b in config.binary_builders:
89 f = open(path.last_req_no_file, "w")
90 f.write("%d\n" % max_no)