]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/rpm_builder.py
- use builtin python3 urllib instead of urllib2
[tld-builder.git] / TLD_Builder / rpm_builder.py
index 80677d52de68a0146c26e04745b4ba95ed46a47e..65ab8e21513653a3415a4960d0da1a87f9be6592 100644 (file)
@@ -9,7 +9,6 @@ import time
 import datetime
 import string
 import urllib
-import urllib2
 
 from config import config, init_conf
 from bqueue import B_Queue
@@ -51,7 +50,7 @@ def pick_request(q):
             return cmp(r1.time, r2.time)
         else:
             return pri_diff
-    q.requests.sort(key=mycmp)
+    q.requests.sort(key=util.cmp_to_key(mycmp))
     ret = q.requests[0]
     return ret
 
@@ -62,12 +61,12 @@ def check_skip_build(r, b):
     while not good:
         try:
             headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
-            req = urllib2.Request(url=src_url, headers=headers)
-            f = urllib2.urlopen(req)
+            req = urllib.request.Request(url=src_url, headers=headers)
+            f = urllib.request.urlopen(req)
             good = True
-        except urllib2.HTTPError as error:
+        except urllib.error.HTTPError as error:
             return False
-        except urllib2.URLError as error:
+        except urllib.error.URLError as error:
             # see errno.h
             try:
                 errno = error.errno
@@ -85,17 +84,17 @@ def check_skip_build(r, b):
     return False
 
 def fetch_src(r, b):
-    src_url = config.control_url + "/srpms/" + r.id + "/" + urllib.quote(b.src_rpm)
+    src_url = config.control_url + "/srpms/" + r.id + "/" + urllib.parse.quote(b.src_rpm)
     b.log_line("fetching %s" % src_url)
     start = time.time()
     good = False
     while not good:
         try:
             headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
-            req = urllib2.Request(url=src_url, headers=headers)
-            f = urllib2.urlopen(req)
+            req = urllib.request.Request(url=src_url, headers=headers)
+            f = urllib.request.urlopen(req)
             good = True
-        except urllib2.HTTPError as error:
+        except urllib.error.HTTPError as error:
             # fail in a way where cron job will retry
             msg = "unable to fetch url %s, http code: %d" % (src_url, error.code)
             b.log_line(msg)
@@ -107,7 +106,7 @@ def fetch_src(r, b):
                 msg = "in queue for more than 6 hours, download failing"
                 b.log_line(msg)
                 return False
-        except urllib2.URLError as error:
+        except urllib.error.URLError as error:
             errno = 0
             if isinstance(error.args[0], IOError):
                 errno = error.args[0].errno
@@ -126,7 +125,7 @@ def fetch_src(r, b):
                     print("error.reason exception %s" % e)
                 raise
 
-    o = chroot.popen("cat > %s" % b.src_rpm, mode = "w")
+    o = chroot.popen("cat > %s" % b.src_rpm, mode = "wb")
 
     try:
         bytes = util.sendfile(f, o)