pld-builder.new: PLD_Builder/rpm_builder.py - try to use urllib2 instead of...

arekm arekm at pld-linux.org
Wed Jul 15 16:01:14 CEST 2009


Author: arekm                        Date: Wed Jul 15 14:01:14 2009 GMT
Module: pld-builder.new               Tag: HEAD
---- Log message:
- try to use urllib2 instead of urllib; should give us what we need even on python 2.4

---- Files affected:
pld-builder.new/PLD_Builder:
   rpm_builder.py (1.96 -> 1.97) 

---- Diffs:

================================================================
Index: pld-builder.new/PLD_Builder/rpm_builder.py
diff -u pld-builder.new/PLD_Builder/rpm_builder.py:1.96 pld-builder.new/PLD_Builder/rpm_builder.py:1.97
--- pld-builder.new/PLD_Builder/rpm_builder.py:1.96	Wed Jul 15 15:47:49 2009
+++ pld-builder.new/PLD_Builder/rpm_builder.py	Wed Jul 15 16:01:09 2009
@@ -5,7 +5,7 @@
 import atexit
 import time
 import string
-import urllib
+import urllib2
 
 from config import config, init_conf
 from bqueue import B_Queue
@@ -57,16 +57,16 @@
     b.log_line("checking if we should skip the build")
     while not good:
         try:
-            f = urllib.urlopen(src_url)
+            f = urllib2.urlopen(src_url)
             good = True
-        except IOError, error:
-            if error[1][0] == 60 or error[1][0] == 110 or error[1][0] == -3 or error[1][0] == 111 or error[1][0] == 61:
+        except urllib2.URLError, error:
+            # see errno.h
+            if error.reason[0] in [-3, 60, 61, 110, 111]:
                 b.log_line("unable to connect... trying again")
                 continue
             else:
                 return False
-        if hasattr(f, 'getcode'):
-            if f.getcode() == 200:
+        except urllib2.HTTPError, error:
                 f.close()
                 return True
         else:
@@ -81,22 +81,21 @@
     good = False
     while not good:
         try:
-            f = urllib.urlopen(src_url)
+            f = urllib2.urlopen(src_url)
             good = True
-        except IOError, error:
-            if error[1][0] == 60 or error[1][0] == 110 or error[1][0] == -3 or error[1][0] == 111 or error[1][0] == 61:
+        except urllib2.URLError, error:
+            # see errno.h
+            if error.reason[0] in [-3, 60, 61, 110, 111]:
                 b.log_line("unable to connect... trying again")
                 continue
             else:
                 raise
-        if hasattr(f, 'getcode'):
-            http_code = f.getcode()
-            if http_code != 200:
-                    # fail in a way where cron job will retry
-                    msg = "unable to fetch file, http code: %d" % http_code
-                    b.log_line(msg)
-                    f.close()
-                    raise IOError, msg
+        except urllib2.HTTPError, error:
+            # fail in a way where cron job will retry
+            msg = "unable to fetch file, http code: %d" % error.code
+            b.log_line(msg)
+            f.close()
+            raise IOError, msg
 
     o = chroot.popen("cat > %s" % b.src_rpm, mode = "w")
 
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/pld-builder.new/PLD_Builder/rpm_builder.py?r1=1.96&r2=1.97&f=u



More information about the pld-cvs-commit mailing list