[Yum-devel] [PATCH 2/3] Add argument 'errors' to _getFile and getPackage.
Zdeněk Pavlas
zpavlas at redhat.com
Mon Sep 26 16:07:22 UTC 2011
Don't expect exception, handle errors in 'failfunc' callback.
If argument 'errors' is provided, call it with the error message.
---
yum/yumRepo.py | 51 +++++++++++++++++++++++++++++++--------------------
1 files changed, 31 insertions(+), 20 deletions(-)
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 91b7dde..f42ced7 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -754,7 +754,7 @@ class YumRepository(Repository, config.RepoConf):
def _getFile(self, url=None, relative=None, local=None, start=None, end=None,
copy_local=None, checkfunc=None, text=None, reget='simple',
- cache=True, size=None):
+ cache=True, size=None, errors=None):
"""retrieve file from the mirrorgroup for the repo
relative to local, optionally get range from
start to end, also optionally retrieve from a specific baseurl"""
@@ -803,11 +803,13 @@ class YumRepository(Repository, config.RepoConf):
dirstat = os.statvfs(os.path.dirname(local))
avail = dirstat.f_bavail * dirstat.f_bsize
if avail < long(size):
- raise Errors.RepoError, _('''\
+ errstr = _('''\
Insufficient space in download directory %s
* free %s
* needed %s'''
) % (os.path.dirname(local), format_number(avail), format_number(long(size)))
+ if errors: return errors(errstr)
+ raise Errors.RepoError(errstr)
if url and scheme != "media":
ugopts = self._default_grabopts(cache=cache)
@@ -822,45 +824,53 @@ Insufficient space in download directory %s
remote = url + '/' + relative
- try:
- result = ug.urlgrab(misc.to_utf8(remote), local,
- text=misc.to_utf8(text),
- range=(start, end),
- )
- except URLGrabError, e:
+ def failfunc(opts):
+ e = opts.exception
errstr = "failed to retrieve %s from %s\nerror was %s" % (relative, self.id, e)
if self.mirrorurls:
errstr +="\n You could try running: yum clean expire-cache"
errstr +="\n To get a new set of mirrors."
+ if errors:
+ return errors(errstr)
if e.errno == 256:
raise Errors.NoMoreMirrorsRepoError, errstr
else:
raise Errors.RepoError, errstr
+ result = ug.urlgrab(
+ misc.to_utf8(remote), local,
+ text=misc.to_utf8(text),
+ range=(start, end),
+ failfunc=failfunc,
+ )
+
else:
headers = tuple(self.__headersListFromDict(cache=cache))
- try:
- result = self.grab.urlgrab(misc.to_utf8(relative), local,
- text = misc.to_utf8(text),
- range = (start, end),
- copy_local=copy_local,
- reget = reget,
- checkfunc=checkfunc,
- http_headers=headers,
- size=size
- )
- except URLGrabError, e:
+
+ def failfunc(opts):
+ e = opts.exception
errstr = "failure: %s from %s: %s" % (relative, self.id, e)
+ if errors:
+ return errors(errstr)
if e.errno == 256:
raise Errors.NoMoreMirrorsRepoError, errstr
else:
raise Errors.RepoError, errstr
+ result = self.grab.urlgrab(
+ misc.to_utf8(relative), local,
+ text = misc.to_utf8(text), range = (start, end),
+ copy_local=copy_local,
+ reget = reget,
+ checkfunc=checkfunc, failfunc=failfunc,
+ http_headers=headers,
+ size=size,
+ )
return result
__get = _getFile
- def getPackage(self, package, checkfunc=None, text=None, cache=True):
+ def getPackage(self, package, checkfunc=None, text=None, cache=True, errors=None):
remote = package.relativepath
local = package.localPkg()
basepath = package.basepath
@@ -877,6 +887,7 @@ Insufficient space in download directory %s
text=text,
cache=cache,
size=package.size,
+ errors=errors,
)
def getHeader(self, package, checkfunc = None, reget = 'simple',
--
1.7.4.4
More information about the Yum-devel
mailing list