Hi list,

I've tried to use `urlgrabber` in a system w/ default Python3 interpreter...
The result (produced mostly by 2to3) is in the patch attached.
I'm not in the list, so in case of questions/notes please CC me.
diff -u -r urlgrabber-3.10.1.org/scripts/urlgrabber urlgrabber-3.10.1/scripts/urlgrabber
--- urlgrabber-3.10.1.org/scripts/urlgrabber	2013-08-26 11:09:07.000000000 +0400
+++ urlgrabber-3.10.1/scripts/urlgrabber	2014-06-05 20:41:41.000000000 +0400
@@ -11,9 +11,9 @@
 #   Lesser General Public License for more details.
 #
 #   You should have received a copy of the GNU Lesser General Public
-#   License along with this library; if not, write to the 
-#      Free Software Foundation, Inc., 
-#      59 Temple Place, Suite 330, 
+#   License along with this library; if not, write to the
+#      Free Software Foundation, Inc.,
+#      59 Temple Place, Suite 330,
 #      Boston, MA  02111-1307  USA
 
 # This file is part of urlgrabber, a high-level cross-protocol url-grabber
@@ -57,7 +57,7 @@
      'http://foo.com/index.html' will be written to 'index.html'.  You
      can override this for your convenience or when necessary for urls
      like 'http://foo.com/'
-     
+
   -O
 
      Print the local name of each downloaded file to STDOUT.  This is
@@ -84,7 +84,7 @@
 
      Turn on internal urlgrabber debugging.  This is equivalent (but
      overrides) running with the environment variable:
-       URLGRABBER_DEBUG=SPEC 
+       URLGRABBER_DEBUG=SPEC
      SPEC can be of the form LEVEL,FILENAME, where
      LEVEL can be string (DEBUG, WARN, etc) or number.
      FILENAME can be the name of a file or "-" for STDOUT.  The
@@ -94,13 +94,14 @@
 
   -D
 
-     A convenience alias for: --verbose=3 --progress --debug=INFO,- 
+     A convenience alias for: --verbose=3 --progress --debug=INFO,-
 
   --profile
 
      Profile the actual fetching and print the results.
 
 """
+from __future__ import print_function
 
 MAINHELP = """usage: urlgrabber [options] <url>
 urlgrabber - a simple client for the urlgrabber python package
@@ -127,7 +128,7 @@
                     turn on urlgrabber module debugging with
                     SPEC=LEVEL,FILENAME.  e.g. -d 1,debug.txt
   -D                a convenience option equivalent to:
-                    --verbose=3 --progress --debug=INFO,- 
+                    --verbose=3 --progress --debug=INFO,-
   --profile         profile the actual fetching and print the results
   """
 
@@ -144,21 +145,21 @@
     def __init__(self):
         self.ug_options, self.ug_defaults = self.get_ug_options()
         self.process_command_line()
-    
+
     def get_ug_options(self):
         ugo = URLGrabberOptions()
         ug_options = ['copy_local', 'keepalive', 'prefix', 'reget',
                       'data', 'quote', 'throttle', 'bandwidth',
                       'proxies', 'retry', 'retrycodes',
-                      'range', 'user_agent', 
-                      'http_headers', 'ftp_headers', 
+                      'range', 'user_agent',
+                      'http_headers', 'ftp_headers',
                       'ssl_ca_cert', 'ssl_context',
                       'text', 'close_connection',
                       'cache_openers','timeout']
         options_exclude = ['delegate', 'interrupt_callback',
                            'failure_callback', 'urlparser', 'opener',
                            'checkfunc', 'progress_obj']
-        for k in ugo.__dict__.keys():
+        for k in list(ugo.__dict__.keys()):
             if (k not in ug_options) and (k not in options_exclude):
                 ug_options.append(k)
                 #print k
@@ -178,8 +179,8 @@
         try:
             optlist, args = getopt.getopt(sys.argv[1:], short_options,
                                           long_options + ug_long)
-        except getopt.GetoptError, e:
-            print >>sys.stderr, "Error:", e
+        except getopt.GetoptError as e:
+            print("Error:", e, file=sys.stderr)
             self.help([], ret=1)
 
         self.verbose = 0
@@ -191,7 +192,7 @@
         self.profile = 0
         self.ugops = {}
         self.args = args
-        
+
         ug_dash = [ '--' + o for o in self.ug_options ]
         if not args: self.help(args)
         for (o, v) in optlist:
@@ -209,7 +210,7 @@
                     self.repeat = int(v)
                     if self.repeat < 1: raise ValueError()
                 except ValueError:
-                    print 'ERROR: repeat value must be an int >= 1'
+                    print('ERROR: repeat value must be an int >= 1')
                     sys.exit(1)
             if o == '-D':
                 self.verbose = 3
@@ -218,20 +219,20 @@
             if o in ug_dash:
                 try:
                     val = eval(v)
-                except Exception, e:
-                    print "error processing option value: %s" % v
-                    print e
+                except Exception as e:
+                    print("error processing option value: %s" % v)
+                    print(e)
                     sys.exit(1)
                 else:
                     self.ugops[o[2:]] = val
 
         if len(self.args) > 1 and self.outputfile is not None:
-            print "ERROR: cannot use -o when grabbing multiple files"
+            print("ERROR: cannot use -o when grabbing multiple files")
             sys.exit(1)
 
     def help(self, args, ret=0):
         if not args:
-            print MAINHELP
+            print(MAINHELP)
         else:
             for a in args:
                 m = getattr(self, 'help_'+a, None)
@@ -240,20 +241,20 @@
                 elif a in self.ug_options:
                     self.help_ug_option(a)
                 else:
-                    print 'ERROR: no help on command "%s"' % a
+                    print('ERROR: no help on command "%s"' % a)
         sys.exit(ret)
 
     def help_doc(self):
-        print __doc__
+        print(__doc__)
 
     def help_options(self):
-        width = max(map(len, self.ug_options))
+        width = max(list(map(len, self.ug_options)))
         format  = '  %-' + str(width) + 's = %s'
         hformat = '  %-' + str(width) + 's   %s'
-        print hformat % ('OPTION', 'DEFAULT')
-        print '-'*(width + 20)
+        print(hformat % ('OPTION', 'DEFAULT'))
+        print('-'*(width + 20))
         for k in self.ug_options:
-            print format % (k, self.ug_defaults[k])
+            print(format % (k, self.ug_defaults[k]))
 
     def help_all(self):
         for k in self.ug_options:
@@ -264,21 +265,21 @@
         m = re.search(r'^(  '+option+'.*?)\s*^ {,2}\S',
                      urlgrabber.grabber.__doc__, re.M|re.S)
         if m:
-            print m.group(1)
+            print(m.group(1))
         else:
-            print '  %s:  no help found for this option' % option
-        print ''
-            
+            print('  %s:  no help found for this option' % option)
+        print('')
+
 class ugclient:
     def __init__(self):
         op = client_options()
         self.op = op
         if op.verbose >= 2 and op.ugops:
-            print "Module Options:"
-            width = max(map(len, op.ugops.keys()))
+            print("Module Options:")
+            width = max(list(map(len, list(op.ugops.keys()))))
             format = "  %-" + str(width) + "s = %s"
-            for k, v in op.ugops.items():
-                print format % (k, repr(v))
+            for k, v in list(op.ugops.items()):
+                print(format % (k, repr(v)))
 
         if op.debug:
             self.set_debug_logger(op.debug)
@@ -294,15 +295,15 @@
 
     def run(self):
         for url in self.op.args:
-            if self.op.verbose: print 'grabbing: %s' % url
+            if self.op.verbose: print('grabbing: %s' % url)
             try:
                 for i in range(0, self.op.repeat):
                     f = self.g.urlgrab(url, self.op.outputfile)
-                if self.op.localfile: print f
-            except URLGrabError, e:
-                print e
+                if self.op.localfile: print(f)
+            except URLGrabError as e:
+                print(e)
                 sys.exit(1)
-        
+
     def set_debug_logger(self, dbspec):
         try:
             dbinfo = dbspec.split(',')
@@ -310,7 +311,7 @@
             level = logging._levelNames.get(dbinfo[0], None)
             if level is None: level = int(dbinfo[0])
             if level < 1: raise ValueError()
-            
+
             formatter = logging.Formatter('%(asctime)s %(message)s')
             if len(dbinfo) > 1: filename = dbinfo[1]
             else: filename = ''
diff -u -r urlgrabber-3.10.1.org/scripts/urlgrabber-ext-down urlgrabber-3.10.1/scripts/urlgrabber-ext-down
--- urlgrabber-3.10.1.org/scripts/urlgrabber-ext-down	2013-08-26 11:09:07.000000000 +0400
+++ urlgrabber-3.10.1/scripts/urlgrabber-ext-down	2014-06-05 17:52:43.000000000 +0400
@@ -25,7 +25,7 @@
 
 def write(fmt, *arg):
     try: os.write(1, fmt % arg)
-    except OSError, e:
+    except OSError as e:
         if e.args[0] != errno.EPIPE: raise
         sys.exit(1)
 
@@ -66,7 +66,7 @@
                     dlsz = fo._tm_last[0] - fo._tm_first[0]
                     dltm = fo._tm_last[1] - fo._tm_first[1]
                 ug_err = 'OK'
-            except URLGrabError, e:
+            except URLGrabError as e:
                 size = 0
                 ug_err = '%d %d %s' % (e.errno, getattr(e, 'code', 0), e.strerror)
             write('%d %d %d %.3f %s\n', opts._id, size, dlsz, dltm, ug_err)
_______________________________________________
Yum-devel mailing list
Yum-devel@lists.baseurl.org
http://lists.baseurl.org/mailman/listinfo/yum-devel

Reply via email to