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()))
29 f = urllib.urlopen(control_url + "/max_req_no")
33 if int(string.strip(f.readline())) != last_count:
38 def fetch_queue(control_url):
39 f = urllib.urlopen(control_url + "/queue.gz")
40 sio = StringIO.StringIO()
44 f = gzip.GzipFile(fileobj = sio)
45 (signers, body) = gpg.verify_sig(f)
46 u = acl.user_by_email(signers)
48 log.alert("queue.gz not signed with signature of valid user: %s" % signers)
50 if not u.can_do("sign_queue", "all"):
51 log.alert("user %s is not allowed to sign my queue" % u.login)
54 return request.parse_requests(body)
56 def handle_reqs(builder, reqs):
57 qpath = path.queue_file + "-" + builder
58 if not os.access(qpath, os.F_OK):
59 util.append_to(qpath, "<queue/>\n")
65 raise 'handle_reqs: fatal: huh? %s' % r.kind
68 if builder in b.builders:
71 log.notice("queued %s (%d) for %s" % (r.id, r.no, builder))
77 lck = lock.lock("request_fetcher")
80 status.push("fetching requests")
81 if has_new(config.control_url):
82 q = fetch_queue(config.control_url)
90 for b in config.binary_builders:
92 f = open(path.last_req_no_file, "w")
93 f.write("%d\n" % max_no)
98 if __name__ == '__main__':
99 # http connection is established (and few bytes transferred through it)
100 # each $secs seconds.
101 loop.run_loop(main, secs = 10)