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
|
|
|
|
# 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.
|
|
|
|
|
2006-10-10 22:08:38 +00:00
|
|
|
import yum
|
2006-10-12 04:38:36 +00:00
|
|
|
import os
|
2006-10-10 22:08:38 +00:00
|
|
|
|
2006-10-11 22:53:52 +00:00
|
|
|
class Gather(yum.YumBase):
|
2006-10-12 14:37:34 +00:00
|
|
|
def __init__(self, opts, 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-10-12 04:38:36 +00:00
|
|
|
self.doConfigSetup(fn=opts.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-10-17 05:38:16 +00:00
|
|
|
if opts.arch == 'i386':
|
2006-10-17 06:07:51 +00:00
|
|
|
arches = yum.rpmUtils.arch.getArchList('i686')
|
|
|
|
else:
|
|
|
|
arches = yum.rpmUtils.arch.getArchList(opts.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-10-11 22:53:52 +00:00
|
|
|
self.opts = opts
|
2006-10-12 14:37:34 +00:00
|
|
|
self.pkglist = pkglist
|
|
|
|
self.polist = []
|
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-10-12 04:38:36 +00:00
|
|
|
if not self.opts.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)
|
|
|
|
for provide in provides:
|
|
|
|
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)
|
|
|
|
for match in matches:
|
|
|
|
unprocessed_pkgs[match] = None
|
2006-10-16 03:03:45 +00:00
|
|
|
|
|
|
|
if not self.opts.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-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-10-12 04:38:36 +00:00
|
|
|
if not self.opts.quiet:
|
|
|
|
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-10-17 04:21:40 +00:00
|
|
|
pkgdir = os.path.join(self.opts.destdir, self.opts.arch, 'Fedora') # Package location within destdir, name subject to change/config
|
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-10-14 23:11:46 +00:00
|
|
|
local = os.path.join(self.opts.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-10-12 04:38:36 +00:00
|
|
|
if not self.opts.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-10-12 04:38:36 +00:00
|
|
|
if not self.opts.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.
|
|
|
|
repo.getPackage(pkg)
|
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-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-16 03:59:41 +00:00
|
|
|
print >> sys.stderr, "Error: Cannot 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:
|
|
|
|
print >> sys.stderr, "Error: Cannot create cache dir %s" % opts.destdir
|
|
|
|
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()
|