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)
|
2006-11-17 23:01:10 +00:00
|
|
|
self.doConfigSetup(fn=config.get('default', 'yumconf'))
|
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()
|
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')
|
|
|
|
else:
|
2006-11-17 23:01:10 +00:00
|
|
|
arches = yum.rpmUtils.arch.getArchList(config.get('default', 'arch'))
|
2006-10-16 03:59:41 +00:00
|
|
|
self.doSackSetup(arches)
|
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 = []
|
2006-10-11 22:53:52 +00:00
|
|
|
|
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
|
|
|
|
2006-10-14 21:43:13 +00:00
|
|
|
reqs = po.requires;
|
2006-10-16 22:29:12 +00:00
|
|
|
pkgresults = {}
|
2006-10-11 22:53:52 +00:00
|
|
|
|
|
|
|
for req in reqs:
|
|
|
|
(r,f,v) = req
|
|
|
|
if r.startswith('rpmlib('):
|
|
|
|
continue
|
|
|
|
|
2006-10-16 22:29:12 +00:00
|
|
|
provides = self.whatProvides(r, f, v)
|
2006-11-28 03:17:29 +00:00
|
|
|
for provide in provides.returnNewestByNameArch():
|
2006-10-16 22:29:12 +00:00
|
|
|
if not pkgresults.has_key(provide):
|
|
|
|
pkgresults[provide] = 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
|
|
|
|
2006-10-12 14:37:34 +00:00
|
|
|
for pkg in self.pkglist: # cycle through our package list and get repo matches
|
2006-10-16 05:11:08 +00:00
|
|
|
matches = self.pkgSack.searchNevra(name=pkg)
|
2006-11-28 03:17:29 +00:00
|
|
|
mysack = yum.packageSack.ListPackageSack(matches)
|
|
|
|
|
|
|
|
for match in mysack.returnNewestByNameArch():
|
2006-10-16 05:11:08 +00:00
|
|
|
unprocessed_pkgs[match] = None
|
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
|
|
|
|
|
|
|
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:
|
2006-12-11 22:13:02 +00:00
|
|
|
srpm = po.returnSimple('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'),
|
2006-11-20 14:52:27 +00:00
|
|
|
self.config.get('default', 'arch'), self.config.get('default', 'osdir'),
|
|
|
|
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)
|
|
|
|
remote = pkg.returnSimple('relativepath')
|
|
|
|
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
|
|
|
|
str(os.path.getsize(local)) == pkg.returnSimple('packagesize')):
|
|
|
|
|
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)
|
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
|
|
|
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'),
|
|
|
|
'source', 'SRPMS')
|
|
|
|
|
|
|
|
if not os.path.exists(pkgdir):
|
|
|
|
os.makedirs(pkgdir)
|
|
|
|
|
|
|
|
for pkg in srpmpolist:
|
|
|
|
repo = self.repos.getRepo(pkg.repoid)
|
|
|
|
remote = pkg.returnSimple('relativepath')
|
|
|
|
local = os.path.basename(remote)
|
|
|
|
local = os.path.join(self.config.get('default', 'cachedir'), local)
|
|
|
|
if os.path.exists(local) and str(os.path.getsize(local)) == pkg.returnSimple('packagesize'):
|
|
|
|
|
|
|
|
if not self.config.has_option('default', 'quiet'):
|
|
|
|
self.logger.info("%s already exists and appears to be complete" % local)
|
|
|
|
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.returnSimple('packagesize'):
|
|
|
|
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)))
|
|
|
|
|
|
|
|
|
2006-10-11 01:05:28 +00:00
|
|
|
def main():
|
|
|
|
# This is used for testing the module
|
2006-10-11 01:19:16 +00:00
|
|
|
(opts, args) = get_arguments()
|
2006-10-10 18:09:34 +00:00
|
|
|
|
2006-10-12 04:38:36 +00:00
|
|
|
pkglist = get_packagelist(opts.comps)
|
|
|
|
|
2006-10-14 22:16:50 +00:00
|
|
|
if not os.path.exists(opts.destdir):
|
|
|
|
try:
|
2006-10-14 23:11:46 +00:00
|
|
|
os.makedirs(opts.destdir)
|
2006-10-14 22:16:50 +00:00
|
|
|
except OSError, e:
|
2006-10-25 18:11:23 +00:00
|
|
|
print >> sys.stderr, "Error: Cannot create destination dir %s" % opts.destdir
|
2006-10-14 22:16:50 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not os.path.exists(opts.cachedir):
|
|
|
|
try:
|
2006-10-24 02:57:30 +00:00
|
|
|
os.makedirs(opts.cachedir)
|
2006-10-14 22:16:50 +00:00
|
|
|
except OSError, e:
|
2006-10-25 18:11:23 +00:00
|
|
|
print >> sys.stderr, "Error: Cannot create cache dir %s" % opts.cachedir
|
2006-10-14 22:16:50 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2006-10-12 14:37:34 +00:00
|
|
|
mygather = Gather(opts, pkglist)
|
|
|
|
mygather.getPackageObjects()
|
|
|
|
mygather.downloadPackages()
|
2006-10-10 18:09:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2006-10-11 01:20:59 +00:00
|
|
|
from optparse import OptionParser
|
2006-10-14 22:16:50 +00:00
|
|
|
import sys
|
|
|
|
|
2006-10-11 01:19:16 +00:00
|
|
|
def get_arguments():
|
|
|
|
# hack job for now, I'm sure this could be better for our uses
|
|
|
|
usage = "usage: %s [options]" % sys.argv[0]
|
|
|
|
parser = OptionParser(usage=usage)
|
|
|
|
parser.add_option("--destdir", default=".", dest="destdir",
|
|
|
|
help='destination directory (defaults to current directory)')
|
2006-10-14 22:16:50 +00:00
|
|
|
parser.add_option("--cachedir", default="./cache", dest="cachedir",
|
|
|
|
help='cache directory (defaults to cache subdir of current directory)')
|
2006-10-11 01:19:16 +00:00
|
|
|
parser.add_option("--comps", default="comps.xml", dest="comps",
|
|
|
|
help='comps file to use')
|
|
|
|
parser.add_option("--yumconf", default="yum.conf", dest="yumconf",
|
|
|
|
help='yum config file to use')
|
2006-10-15 21:30:01 +00:00
|
|
|
parser.add_option("--arch", default="i386", dest="arch",
|
|
|
|
help='Base arch to use')
|
2006-10-12 04:38:36 +00:00
|
|
|
parser.add_option("-q", "--quiet", default=False, action="store_true",
|
|
|
|
help="Output as little as possible")
|
|
|
|
|
2006-10-10 18:09:34 +00:00
|
|
|
|
2006-10-11 01:19:16 +00:00
|
|
|
|
|
|
|
(opts, args) = parser.parse_args()
|
|
|
|
#if len(opts) < 1:
|
|
|
|
# parser.print_help()
|
|
|
|
# sys.exit(0)
|
|
|
|
return (opts, args)
|
|
|
|
|
|
|
|
def get_packagelist(myComps):
|
|
|
|
# Get the list of packages from the comps file
|
2006-10-12 04:38:36 +00:00
|
|
|
try:
|
|
|
|
compsobj = yum.comps.Comps()
|
|
|
|
compsobj.add(myComps)
|
|
|
|
|
|
|
|
except IOError:
|
|
|
|
print >> sys.stderr, "gather.py: No such file:\'%s\'" % opts.comps
|
|
|
|
sys.exit(1)
|
|
|
|
|
2006-10-11 01:19:16 +00:00
|
|
|
pkglist = []
|
2006-10-12 04:38:36 +00:00
|
|
|
for group in compsobj.groups:
|
2006-10-11 01:19:16 +00:00
|
|
|
pkglist += group.packages
|
|
|
|
return pkglist
|
2006-10-12 04:38:36 +00:00
|
|
|
|
2006-10-11 01:19:16 +00:00
|
|
|
main()
|