2006-10-10 18:09:34 +00:00
|
|
|
#!/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
|
2006-10-24 13:44:11 +00:00
|
|
|
# the Free Software Foundation; version 2 of the License.
|
2006-10-10 18:09:34 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2006-10-10 22:08:38 +00:00
|
|
|
import yum
|
2006-10-12 04:38:36 +00:00
|
|
|
import os
|
2006-11-17 19:02:37 +00:00
|
|
|
import shutil
|
2006-12-10 01:48:08 +00:00
|
|
|
import sys
|
2006-10-10 22:08:38 +00:00
|
|
|
|
2006-10-11 22:53:52 +00:00
|
|
|
class Gather(yum.YumBase):
|
2006-11-17 23:01:10 +00:00
|
|
|
def __init__(self, config, pkglist):
|
2006-10-12 04:38:36 +00:00
|
|
|
# Create a yum object to use
|
2006-10-11 22:53:52 +00:00
|
|
|
yum.YumBase.__init__(self)
|
2007-01-23 23:03:52 +00:00
|
|
|
self.doConfigSetup(fn=config.get('default', 'yumconf'), debuglevel=6, errorlevel=6, root="/tmp")
|
2006-10-17 03:11:58 +00:00
|
|
|
self.cleanMetadata() # clean metadata that might be in the cache from previous runs
|
2006-10-17 05:38:16 +00:00
|
|
|
self.cleanSqlite() # clean metadata that might be in the cache from previous runs
|
2006-10-12 04:38:36 +00:00
|
|
|
self.doRepoSetup()
|
2007-01-23 23:03:52 +00:00
|
|
|
self.doTsSetup()
|
|
|
|
self.doRpmDBSetup()
|
2006-11-17 23:01:10 +00:00
|
|
|
if config.get('default', 'arch') == 'i386':
|
2006-10-17 06:07:51 +00:00
|
|
|
arches = yum.rpmUtils.arch.getArchList('i686')
|
2007-02-06 18:51:53 +00:00
|
|
|
self.compatarch = 'i686'
|
2006-12-12 17:21:28 +00:00
|
|
|
elif config.get('default', 'arch') == 'ppc':
|
|
|
|
arches = yum.rpmUtils.arch.getArchList('ppc64')
|
2007-02-06 18:51:53 +00:00
|
|
|
self.compatarch = 'ppc64'
|
2006-10-17 06:07:51 +00:00
|
|
|
else:
|
2006-11-17 23:01:10 +00:00
|
|
|
arches = yum.rpmUtils.arch.getArchList(config.get('default', 'arch'))
|
2007-02-06 18:51:53 +00:00
|
|
|
self.compatarch = config.get('default', 'arch')
|
2006-10-16 03:59:41 +00:00
|
|
|
self.doSackSetup(arches)
|
2007-01-23 23:03:52 +00:00
|
|
|
self.doSackFilelistPopulate()
|
2006-10-23 19:50:44 +00:00
|
|
|
self.logger = yum.logging.getLogger("yum.verbose.pungi")
|
2006-11-17 23:01:10 +00:00
|
|
|
self.config = config
|
2006-10-12 14:37:34 +00:00
|
|
|
self.pkglist = pkglist
|
|
|
|
self.polist = []
|
2006-12-10 01:48:08 +00:00
|
|
|
self.srpmlist = []
|
2007-02-07 03:53:43 +00:00
|
|
|
self.resolved_deps = {} # list the deps we've already resolved, short circuit.
|
2006-10-11 22:53:52 +00:00
|
|
|
|
2007-01-23 23:03:52 +00:00
|
|
|
def _provideToPkg(self, req): #this is stolen from Anaconda
|
2007-01-24 21:27:28 +00:00
|
|
|
bestlist = None
|
2007-01-23 23:03:52 +00:00
|
|
|
(r, f, v) = req
|
|
|
|
|
|
|
|
satisfiers = []
|
|
|
|
for po in self.whatProvides(r, f, v):
|
|
|
|
# if we already have something installed which does the provide
|
|
|
|
# then that's obviously the one we want to use. this takes
|
|
|
|
# care of the case that we select, eg, kernel-smp and then
|
|
|
|
# have something which requires kernel
|
|
|
|
if self.tsInfo.getMembers(po.pkgtup):
|
2007-01-24 21:27:28 +00:00
|
|
|
return [po]
|
2007-01-23 23:03:52 +00:00
|
|
|
if po not in satisfiers:
|
|
|
|
satisfiers.append(po)
|
|
|
|
|
|
|
|
if satisfiers:
|
2007-02-06 18:51:53 +00:00
|
|
|
bestlist = self.bestPackagesFromList(satisfiers, arch=self.compatarch)
|
2007-01-24 21:27:28 +00:00
|
|
|
return bestlist
|
2007-01-23 23:03:52 +00:00
|
|
|
return None
|
|
|
|
|
2006-10-16 04:42:43 +00:00
|
|
|
def getPackageDeps(self, po):
|
2006-10-11 22:53:52 +00:00
|
|
|
"""Return the dependencies for a given package, as well
|
|
|
|
possible solutions for those dependencies.
|
|
|
|
|
2006-10-12 04:38:36 +00:00
|
|
|
Returns the deps as a list"""
|
|
|
|
|
2006-10-11 22:53:52 +00:00
|
|
|
|
2006-11-17 23:01:10 +00:00
|
|
|
if not self.config.has_option('default', 'quiet'):
|
2006-10-15 21:30:01 +00:00
|
|
|
self.logger.info('Checking deps of %s.%s' % (po.name, po.arch))
|
2006-10-11 22:53:52 +00:00
|
|
|
|
2007-01-23 23:03:52 +00:00
|
|
|
reqs = po.requires
|
|
|
|
provs = po.provides
|
2006-10-16 22:29:12 +00:00
|
|
|
pkgresults = {}
|
2006-10-11 22:53:52 +00:00
|
|
|
|
|
|
|
for req in reqs:
|
2007-02-07 03:53:43 +00:00
|
|
|
if self.resolved_deps.has_key(req):
|
|
|
|
continue
|
2006-10-11 22:53:52 +00:00
|
|
|
(r,f,v) = req
|
2007-01-23 23:03:52 +00:00
|
|
|
if r.startswith('rpmlib(') or r.startswith('config('):
|
|
|
|
continue
|
|
|
|
if req in provs:
|
|
|
|
continue
|
|
|
|
|
2007-01-24 21:27:28 +00:00
|
|
|
deps = self._provideToPkg(req)
|
|
|
|
if deps is None:
|
2007-01-23 23:03:52 +00:00
|
|
|
self.logger.warning("Unresolvable dependency %s in %s" % (r, po.name))
|
2006-10-11 22:53:52 +00:00
|
|
|
continue
|
|
|
|
|
2007-01-24 21:27:28 +00:00
|
|
|
for dep in deps:
|
|
|
|
if not pkgresults.has_key(dep):
|
|
|
|
pkgresults[dep] = None
|
|
|
|
self.tsInfo.addInstall(dep)
|
2007-02-07 03:53:43 +00:00
|
|
|
|
|
|
|
self.resolved_deps[req] = None
|
2006-10-11 22:53:52 +00:00
|
|
|
|
2006-10-16 22:29:12 +00:00
|
|
|
return pkgresults.keys()
|
2006-10-11 22:53:52 +00:00
|
|
|
|
2006-10-12 14:37:34 +00:00
|
|
|
def getPackageObjects(self):
|
2006-10-12 04:38:36 +00:00
|
|
|
"""Cycle through the list of packages, get package object
|
|
|
|
matches, and resolve deps.
|
|
|
|
|
|
|
|
Returns a list of package objects"""
|
|
|
|
|
|
|
|
|
2006-10-16 05:11:08 +00:00
|
|
|
unprocessed_pkgs = {} # list of packages yet to depsolve ## Use dicts for speed
|
|
|
|
final_pkgobjs = {} # The final list of package objects
|
2006-10-12 04:38:36 +00:00
|
|
|
|
2007-02-09 01:25:41 +00:00
|
|
|
# Search repos for things in our manifest, supports globs
|
|
|
|
(exactmatched, matched, unmatched) = yum.packages.parsePackages(self.pkgSack.returnPackages(), self.pkglist, casematch=1)
|
|
|
|
matches = exactmatched + matched
|
|
|
|
|
|
|
|
# Get the newest results from the search
|
|
|
|
mysack = yum.packageSack.ListPackageSack(matches)
|
|
|
|
for match in mysack.returnNewestByNameArch():
|
|
|
|
unprocessed_pkgs[match] = None
|
|
|
|
self.tsInfo.addInstall(match)
|
2006-10-16 03:03:45 +00:00
|
|
|
|
2006-11-17 23:01:10 +00:00
|
|
|
if not self.config.has_option('default', 'quiet'):
|
2006-10-16 05:11:08 +00:00
|
|
|
for pkg in unprocessed_pkgs.keys():
|
2006-10-16 03:03:45 +00:00
|
|
|
self.logger.info('Found %s.%s' % (pkg.name, pkg.arch))
|
2006-10-12 04:38:36 +00:00
|
|
|
|
2007-02-09 01:25:41 +00:00
|
|
|
for pkg in unmatched:
|
|
|
|
self.logger.warn('Could not find a match for %s' % pkg)
|
|
|
|
|
2006-10-12 04:38:36 +00:00
|
|
|
if len(unprocessed_pkgs) == 0:
|
|
|
|
raise yum.Errors.MiscError, 'No packages found to download.'
|
|
|
|
|
|
|
|
while len(unprocessed_pkgs) > 0: # Our fun loop
|
2006-10-16 05:11:08 +00:00
|
|
|
for pkg in unprocessed_pkgs.keys():
|
|
|
|
if not final_pkgobjs.has_key(pkg):
|
|
|
|
final_pkgobjs[pkg] = None # Add the pkg to our final list
|
2006-10-16 04:42:43 +00:00
|
|
|
deplist = self.getPackageDeps(pkg) # Get the deps of our package
|
2006-10-12 04:38:36 +00:00
|
|
|
|
|
|
|
for dep in deplist: # Cycle through deps, if we don't already have it, add it.
|
2006-10-16 05:11:08 +00:00
|
|
|
if not unprocessed_pkgs.has_key(dep) and not final_pkgobjs.has_key(dep):
|
|
|
|
unprocessed_pkgs[dep] = None
|
2006-10-12 04:38:36 +00:00
|
|
|
|
2006-10-16 05:11:08 +00:00
|
|
|
del unprocessed_pkgs[pkg] # Clear the package out of our todo list.
|
2006-10-16 03:59:41 +00:00
|
|
|
|
2006-10-16 05:11:08 +00:00
|
|
|
self.polist = final_pkgobjs.keys()
|
2006-10-12 04:38:36 +00:00
|
|
|
|
2006-12-10 01:48:08 +00:00
|
|
|
def getSRPMList(self):
|
|
|
|
"""Cycle through the list of package objects and
|
|
|
|
find the sourcerpm for them. Requires yum still
|
|
|
|
configured and a list of package objects"""
|
|
|
|
|
|
|
|
|
|
|
|
for po in self.polist:
|
2007-02-06 18:54:06 +00:00
|
|
|
srpm = po.sourcerpm.split('.src.rpm')[0]
|
2006-12-10 01:48:08 +00:00
|
|
|
if not srpm in self.srpmlist:
|
|
|
|
self.srpmlist.append(srpm)
|
|
|
|
|
|
|
|
|
2006-10-12 14:37:34 +00:00
|
|
|
def downloadPackages(self):
|
2006-10-11 22:53:52 +00:00
|
|
|
"""Cycle through the list of package objects and
|
|
|
|
download them from their respective repos."""
|
|
|
|
|
|
|
|
|
2006-11-17 23:01:10 +00:00
|
|
|
if not self.config.has_option('default', 'quiet'):
|
2006-10-12 04:38:36 +00:00
|
|
|
downloads = []
|
2006-10-12 14:37:34 +00:00
|
|
|
for pkg in self.polist:
|
2006-10-16 03:59:41 +00:00
|
|
|
downloads.append('%s.%s' % (pkg.name, pkg.arch))
|
2006-10-16 04:42:43 +00:00
|
|
|
downloads.sort()
|
2006-10-12 04:38:36 +00:00
|
|
|
self.logger.info("Download list: %s" % downloads)
|
|
|
|
|
2006-11-17 23:01:10 +00:00
|
|
|
# Package location within destdir, name subject to change/config
|
|
|
|
pkgdir = os.path.join(self.config.get('default', 'destdir'), self.config.get('default', 'version'),
|
2007-01-25 04:42:40 +00:00
|
|
|
self.config.get('default', 'flavor'),
|
|
|
|
self.config.get('default', 'arch'),
|
|
|
|
self.config.get('default', 'osdir'),
|
2006-11-20 14:52:27 +00:00
|
|
|
self.config.get('default', 'product_path'))
|
2006-11-17 23:01:10 +00:00
|
|
|
|
2006-10-14 23:11:46 +00:00
|
|
|
if not os.path.exists(pkgdir):
|
|
|
|
os.makedirs(pkgdir)
|
|
|
|
|
2006-10-12 14:37:34 +00:00
|
|
|
for pkg in self.polist:
|
2006-10-11 22:53:52 +00:00
|
|
|
repo = self.repos.getRepo(pkg.repoid)
|
2007-02-06 18:54:06 +00:00
|
|
|
remote = pkg.relativepath
|
2006-10-11 22:53:52 +00:00
|
|
|
local = os.path.basename(remote)
|
2006-11-17 23:01:10 +00:00
|
|
|
local = os.path.join(self.config.get('default', 'cachedir'), local)
|
2006-10-11 22:53:52 +00:00
|
|
|
if (os.path.exists(local) and
|
2007-02-06 18:54:06 +00:00
|
|
|
str(os.path.getsize(local)) == pkg.packagesize):
|
2006-10-11 22:53:52 +00:00
|
|
|
|
2006-11-17 23:01:10 +00:00
|
|
|
if not self.config.has_option('default', 'quiet'):
|
2006-10-11 22:53:52 +00:00
|
|
|
self.logger.info("%s already exists and appears to be complete" % local)
|
2007-02-12 20:57:58 +00:00
|
|
|
target=os.path.join(pkgdir, os.path.basename(remote))
|
2007-02-12 21:29:19 +00:00
|
|
|
if os.path.exists(target):
|
|
|
|
os.remove(target) # avoid traceback after interrupted download
|
2007-02-12 20:57:58 +00:00
|
|
|
os.link(local, target)
|
2006-10-11 22:53:52 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
# Disable cache otherwise things won't download
|
|
|
|
repo.cache = 0
|
2006-11-17 23:01:10 +00:00
|
|
|
if not self.config.has_option('default', 'quiet'):
|
2006-10-11 22:53:52 +00:00
|
|
|
self.logger.info('Downloading %s' % os.path.basename(remote))
|
|
|
|
pkg.localpath = local # Hack: to set the localpath to what we want.
|
2006-11-17 19:02:37 +00:00
|
|
|
|
|
|
|
# do a little dance for file:// repos...
|
|
|
|
path = repo.getPackage(pkg)
|
|
|
|
if not os.path.exists(local) or not os.path.samefile(path, local):
|
|
|
|
shutil.copy2(path, local)
|
|
|
|
|
2006-10-14 23:11:46 +00:00
|
|
|
os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
|
2006-10-11 22:53:52 +00:00
|
|
|
|
|
|
|
|
2006-12-10 01:48:08 +00:00
|
|
|
def downloadSRPMs(self):
|
|
|
|
"""Cycle through the list of srpms and
|
|
|
|
find the package objects for them, Then download them."""
|
|
|
|
|
|
|
|
|
|
|
|
srpmpolist = []
|
|
|
|
|
|
|
|
# Work around for yum bug
|
|
|
|
for sack in self.pkgSack.sacks.values():
|
|
|
|
sack.excludes = {}
|
|
|
|
|
|
|
|
self.pkgSack.excludes = {}
|
|
|
|
|
|
|
|
# We need to reset the yum object
|
|
|
|
self.pkgSack = None
|
|
|
|
|
|
|
|
# Setup the sack with just src arch
|
|
|
|
self.doSackSetup(archlist=['src'])
|
|
|
|
|
|
|
|
for srpm in self.srpmlist:
|
2006-12-11 22:13:02 +00:00
|
|
|
(sname, sver, srel) = srpm.rsplit('-', 2)
|
2006-12-10 01:48:08 +00:00
|
|
|
try:
|
2006-12-10 02:31:00 +00:00
|
|
|
srpmpo = self.pkgSack.searchNevra(name=sname, ver=sver, rel=srel)[0]
|
2006-12-10 01:48:08 +00:00
|
|
|
if not srpmpo in srpmpolist:
|
|
|
|
srpmpolist.append(srpmpo)
|
|
|
|
except IndexError:
|
|
|
|
print >> sys.stderr, "Error: Cannot find a source rpm for %s" % srpm
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# do the downloads
|
|
|
|
pkgdir = os.path.join(self.config.get('default', 'destdir'), self.config.get('default', 'version'),
|
2007-01-25 04:42:40 +00:00
|
|
|
self.config.get('default', 'flavor'), 'source', 'SRPMS')
|
2006-12-10 01:48:08 +00:00
|
|
|
|
|
|
|
if not os.path.exists(pkgdir):
|
|
|
|
os.makedirs(pkgdir)
|
|
|
|
|
|
|
|
for pkg in srpmpolist:
|
|
|
|
repo = self.repos.getRepo(pkg.repoid)
|
2007-02-06 18:54:06 +00:00
|
|
|
remote = pkg.relativepath
|
2006-12-10 01:48:08 +00:00
|
|
|
local = os.path.basename(remote)
|
|
|
|
local = os.path.join(self.config.get('default', 'cachedir'), local)
|
2007-02-06 18:54:06 +00:00
|
|
|
if os.path.exists(local) and str(os.path.getsize(local)) == pkg.packagesize:
|
2006-12-10 01:48:08 +00:00
|
|
|
|
|
|
|
if not self.config.has_option('default', 'quiet'):
|
|
|
|
self.logger.info("%s already exists and appears to be complete" % local)
|
2007-02-06 18:54:06 +00:00
|
|
|
if os.path.exists(os.path.join(pkgdir, os.path.basename(remote))) and str(os.path.getsize(os.path.join(pkgdir, os.path.basename(remote)))) == pkg.packagesize:
|
2006-12-10 01:48:08 +00:00
|
|
|
if not self.config.has_option('default', 'quiet'):
|
|
|
|
self.logger.info("%s already exists in tree and appears to be complete" % local)
|
|
|
|
else:
|
|
|
|
os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Disable cache otherwise things won't download
|
|
|
|
repo.cache = 0
|
|
|
|
if not self.config.has_option('default', 'quiet'):
|
|
|
|
self.logger.info('Downloading %s' % os.path.basename(remote))
|
|
|
|
pkg.localpath = local # Hack: to set the localpath to what we want.
|
|
|
|
|
|
|
|
# do a little dance for file:// repos...
|
|
|
|
path = repo.getPackage(pkg)
|
|
|
|
if not os.path.exists(local) or not os.path.samefile(path, local):
|
|
|
|
shutil.copy2(path, local)
|
|
|
|
|
|
|
|
os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
|