X-Git-Url: https://git.tld-linux.org/?a=blobdiff_plain;f=TLD_Builder%2Frequest_fetcher.py;h=25b130f7007da73017100b542439a032181315d0;hb=9ea122b00e3a99b16246e1e38576916a2e25c0aa;hp=9877cde771572ba4e7a23ca73fa2e2251a639ee2;hpb=b999f53d4bf5d44586ecf028876e8bc20b5fd2ce;p=tld-builder.git diff --git a/TLD_Builder/request_fetcher.py b/TLD_Builder/request_fetcher.py index 9877cde..25b130f 100644 --- a/TLD_Builder/request_fetcher.py +++ b/TLD_Builder/request_fetcher.py @@ -5,10 +5,9 @@ import signal import os import urllib import urllib2 -import StringIO import sys +from io import StringIO import gzip - import path import log import status @@ -26,14 +25,14 @@ from config import config, init_conf 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() @@ -45,9 +44,9 @@ def has_new(control_url): 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())) + 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) @@ -66,18 +65,18 @@ def fetch_queue(control_url): req = urllib2.Request(url=control_url + "/queue.gz", headers=headers) f = urllib2.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 = StringIO() 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) @@ -99,7 +98,7 @@ def handle_reqs(builder, reqs): 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: