import signal
import os
import urllib
-import urllib2
-import StringIO
import sys
+from io import StringIO, BytesIO
import gzip
-
import path
import log
import status
last_count = 0
def alarmalarm(signum, frame):
- raise IOError, 'TCP connection hung'
+ raise IOError('TCP connection hung')
def has_new(control_url):
global last_count
cnt_f = open(path.last_req_no_file)
try:
- last_count = int(string.strip(cnt_f.readline()))
- except ValueError, e:
+ last_count = int(cnt_f.readline().strip())
+ except ValueError as e:
last_count = 0
cnt_f.close()
signal.alarm(300)
try:
headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
- req = urllib2.Request(url=control_url + "/max_req_no", headers=headers)
- f = urllib2.urlopen(req)
- count = int(string.strip(f.readline()))
+ req = urllib.request.Request(url=control_url + "/max_req_no", headers=headers)
+ f = urllib.request.urlopen(req)
+ count = int(f.readline().strip())
signal.alarm(0)
- except Exception, e:
+ except Exception as e:
signal.alarm(0)
log.error("can't fetch %s: %s" % (control_url + "/max_req_no", e))
sys.exit(1)
signal.alarm(300)
try:
headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
- req = urllib2.Request(url=control_url + "/queue.gz", headers=headers)
- f = urllib2.urlopen(req)
+ req = urllib.request.Request(url=control_url + "/queue.gz", headers=headers)
+ f = urllib.request.urlopen(req)
signal.alarm(0)
- except Exception, e:
+ except Exception as e:
signal.alarm(0)
log.error("can't fetch %s: %s" % (control_url + "/queue.gz", e))
sys.exit(1)
- sio = StringIO.StringIO()
+ sio = BytesIO()
util.sendfile(f, sio)
f.close()
sio.seek(0)
f = gzip.GzipFile(fileobj = sio)
try:
fdata = f.read()
- except struct.error, e:
+ except struct.error as e:
log.alert("corrupted fetched queue.gz file")
sys.exit(1)
(signers, body) = gpg.verify_sig(fdata)
q.read()
for r in reqs:
if r.kind != 'group':
- raise Exception, 'handle_reqs: fatal: huh? %s' % r.kind
+ raise Exception('handle_reqs: fatal: huh? %s' % r.kind)
need_it = 0
for b in r.batches:
if builder in b.builders: