#! /usr/bin/python -tt # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # # Copyright Red Hat Inc. 2007 # # Author: James Antill # Use just like normal, but all package downloads happen via. CURL. import yum from yum.plugins import TYPE_CORE requires_api_version = '2.5' plugin_type = (TYPE_CORE,) def mediasort(a, b): # FIXME: we should probably also use the mediaid; else we # could conceivably ping-pong between different disc1's a = a.getDiscNum() b = b.getDiscNum() if a is None: return -1 if b is None: return 1 if a < b: return -1 elif a > b: return 1 return 0 def predownload_hook(conduit, pkglist): """ Download via. curl. """ self = conduit._base # Hack tastic, so we can merge into core easier remote_pkgs = [] for po in pkglist: if hasattr(po, 'pkgtype') and po.pkgtype == 'local': continue local = po.localPkg() if os.path.exists(local): cursize = os.stat(local)[6] totsize = long(po.size) if not po.verifyLocalPkg(): if po.repo.cache: repo_cached = True adderror(po, 'package fails checksum but caching is ' 'enabled for %s' % po.repo.id) if cursize >= totsize: # otherwise keep it around for regetting os.unlink(local) else: continue remote_pkgs.append(po) # caching is enabled and the package # just failed to check out there's no # way to save this, report the error and return if (self.conf.cache or repo_cached) and errors: return remote_pkgs.sort(mediasort) i = 0 for po in remote_pkgs: i += 1 checkfunc = (self.verifyPkg, (po, 1), {}) dirstat = os.statvfs(po.repo.pkgdir) if (dirstat.f_bavail * dirstat.f_bsize) <= long(po.size): adderror(po, 'Insufficient space in download directory %s ' 'to download' % po.repo.pkgdir) continue try: text = '(%s/%s): %s' % (i, len(remote_pkgs), os.path.basename(po.relativepath)) mylocal = getPackage(po, checkfunc=checkfunc, text=text, cache=po.repo.http_caching != 'none', ) except Errors.RepoError, e: adderror(po, str(e)) else: po.localpath = mylocal if errors.has_key(po): del errors[po]