[Yum-devel] [PATCH 2/3] Add argument 'errorfunc' to _getFile and getPackage.

Zdenek Pavlas zpavlas at redhat.com
Wed Jan 4 15:45:49 UTC 2012


> >      def _getFile(self, url=None, relative=None, local=None,
> > ...
> > -            cache=True, size=None):
> > +            cache=True, size=None, errorfunc=None):
> 
>  Just a minor thing, but this will break rhn-plugin ...

Uh, really, this raises TypeError :(
Always amazed how simple things turn out to be complex.

> so can you open a  BZ for them to add this arg?

It's not enough to just add an arg.  The caller expects that
errorfunc is called on failures instead of raising an exception.

This requires wrapping whole RhnRepo._getFile(), and the wrapper
does not have to be in the same class..  I think it's better to
do that in yum:

Author: Zdeněk Pavlas <zpavlas at redhat.com>
Date:   Wed Jan 4 16:11:23 2012 +0100

    _getFile() compat wrapper to support plugins.

diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 1bde6fc..e03fbc1 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -37,6 +37,7 @@ from yum import config
 from yum import misc
 from yum import comps
 from yum import _
+from yum.i18n import exception2msg
 from constants import *
 import metalink
 
@@ -906,6 +907,23 @@ Insufficient space in download directory %s
                 return local
             misc.unlink_f(local)
 
+        if not 'errorfunc' in self._getFile.im_func.func_code.co_varnames:
+            # the derived _getFile() does not support 'errorfunc' argument.
+            # turn exceptions to callbacks there to keep caller happy.
+            try:
+                return self._getFile(url=basepath,
+                                relative=remote,
+                                local=local,
+                                checkfunc=checkfunc,
+                                text=text,
+                                cache=cache,
+                                size=package.size,
+                                )
+            except URLGrabError, e:
+                if errorfunc:
+                    return errorfunc(exception2msg(e))
+                raise e
+
         return self._getFile(url=basepath,
                         relative=remote,
                         local=local,


More information about the Yum-devel mailing list