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