]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/request_fetcher.py
- python 3.x fixes
[tld-builder.git] / TLD_Builder / request_fetcher.py
index 9877cde771572ba4e7a23ca73fa2e2251a639ee2..609ec711bcf644425bc247a671e6df4a45e44339 100644 (file)
@@ -5,8 +5,11 @@ import signal
 import os
 import urllib
 import urllib2
-import StringIO
 import sys
+if sys.version_info[0] == 2:
+    import StringIO
+else:
+    from io import StringIO
 import gzip
 
 import path
@@ -26,14 +29,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 +48,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,7 +69,7 @@ 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)
@@ -77,7 +80,7 @@ def fetch_queue(control_url):
     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 +102,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: