First pass at using a config file for options rather than CLI

Much churn, add a new config file.  Seems to still work
This commit is contained in:
jkeating@harpoon.lab.boston.redhat.com 2006-11-17 18:01:10 -05:00 committed by Jesse Keating
parent 8bddcaef54
commit 95f6a0b642
4 changed files with 102 additions and 70 deletions

12
config/pungi.conf Normal file
View File

@ -0,0 +1,12 @@
# Pungi config file
#
[default]
product_name = Fedora
comps = /etc/pungi/comps.xml
yumconf = /etc/pungi/yum.conf.x86_64
destdir = /srv/pungi
cachedir = /srv/pungi/cache
arch = x86_64
version = 6.89
discs = 1

62
pungi
View File

@ -17,31 +17,39 @@ import pypungi.gather
import pypungi.pungi
import yum
from ConfigParser import SafeConfigParser
def main():
# This is used for testing the module
(opts, args) = get_arguments()
pkglist = get_packagelist(opts.comps)
config = SafeConfigParser()
config.read(opts.config)
if not os.path.exists(opts.destdir):
pkglist = get_packagelist(config.get('default', 'comps'))
destdir = config.get('default', 'destdir')
if not os.path.exists(destdir):
try:
os.makedirs(opts.destdir)
os.makedirs(destdir)
except OSError, e:
print >> sys.stderr, "Error: Cannot create destination dir %s" % opts.destdir
print >> sys.stderr, "Error: Cannot create destination dir %s" % destdir
sys.exit(1)
if not os.path.exists(opts.cachedir):
cachedir = config.get('default', 'cachedir')
if not os.path.exists(cachedir):
try:
os.makedirs(opts.cachedir)
os.makedirs(cachedir)
except OSError, e:
print >> sys.stderr, "Error: Cannot create cache dir %s" % opts.cachedir
print >> sys.stderr, "Error: Cannot create cache dir %s" % cachedir
sys.exit(1)
mygather = pypungi.gather.Gather(opts, pkglist)
mygather = pypungi.gather.Gather(config, pkglist)
mygather.getPackageObjects()
mygather.downloadPackages()
mypungi = pypungi.pungi.Pungi(opts)
mypungi = pypungi.pungi.Pungi(config)
mypungi.doBuildinstall()
mypungi.doPackageorder()
mypungi.doSplittree()
@ -57,22 +65,24 @@ if __name__ == '__main__':
# 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)')
parser.add_option("--cachedir", default="./cache", dest="cachedir",
help='cache directory (defaults to cache subdir of current directory)')
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')
parser.add_option("--arch", default="i386", dest="arch",
help='Base arch to use')
parser.add_option("--version", default="test", dest="version",
help='Version of the spin')
parser.add_option("--discs", default=5, type="int", dest="discs",
help='Number of discs to spin')
parser.add_option("-q", "--quiet", default=False, action="store_true",
help="Output as little as possible")
# parser.add_option("--destdir", default=".", dest="destdir",
# help='destination directory (defaults to current directory)')
# parser.add_option("--cachedir", default="./cache", dest="cachedir",
# help='cache directory (defaults to cache subdir of current directory)')
# 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')
# parser.add_option("--arch", default="i386", dest="arch",
# help='Base arch to use')
# parser.add_option("--version", default="test", dest="version",
# help='Version of the spin')
# parser.add_option("--discs", default=5, type="int", dest="discs",
# help='Number of discs to spin')
# parser.add_option("-q", "--quiet", default=False, action="store_true",
# help="Output as little as possible")
parser.add_option("-c", "--conf", default='/etc/pungi/pungi.conf', dest="config",
help='Config file to use')

View File

@ -17,20 +17,20 @@ import os
import shutil
class Gather(yum.YumBase):
def __init__(self, opts, pkglist):
def __init__(self, config, pkglist):
# Create a yum object to use
yum.YumBase.__init__(self)
self.doConfigSetup(fn=opts.yumconf)
self.doConfigSetup(fn=config.get('default', 'yumconf'))
self.cleanMetadata() # clean metadata that might be in the cache from previous runs
self.cleanSqlite() # clean metadata that might be in the cache from previous runs
self.doRepoSetup()
if opts.arch == 'i386':
if config.get('default', 'arch') == 'i386':
arches = yum.rpmUtils.arch.getArchList('i686')
else:
arches = yum.rpmUtils.arch.getArchList(opts.arch)
arches = yum.rpmUtils.arch.getArchList(config.get('default', 'arch'))
self.doSackSetup(arches)
self.logger = yum.logging.getLogger("yum.verbose.pungi")
self.opts = opts
self.config = config
self.pkglist = pkglist
self.polist = []
@ -41,7 +41,7 @@ class Gather(yum.YumBase):
Returns the deps as a list"""
if not self.opts.quiet:
if not self.config.has_option('default', 'quiet'):
self.logger.info('Checking deps of %s.%s' % (po.name, po.arch))
reqs = po.requires;
@ -74,7 +74,7 @@ class Gather(yum.YumBase):
for match in matches:
unprocessed_pkgs[match] = None
if not self.opts.quiet:
if not self.config.has_option('default', 'quiet'):
for pkg in unprocessed_pkgs.keys():
self.logger.info('Found %s.%s' % (pkg.name, pkg.arch))
@ -100,14 +100,17 @@ class Gather(yum.YumBase):
download them from their respective repos."""
if not self.opts.quiet:
if not self.config.has_option('default', 'quiet'):
downloads = []
for pkg in self.polist:
downloads.append('%s.%s' % (pkg.name, pkg.arch))
downloads.sort()
self.logger.info("Download list: %s" % downloads)
pkgdir = os.path.join(self.opts.destdir, self.opts.version, self.opts.arch, 'os', 'Fedora') # Package location within destdir, name subject to change/config
# Package location within destdir, name subject to change/config
pkgdir = os.path.join(self.config.get('default', 'destdir'), self.config.get('default', 'version'),
self.config.get('default', 'arch'), 'os', 'Fedora')
if not os.path.exists(pkgdir):
os.makedirs(pkgdir)
@ -115,18 +118,18 @@ class Gather(yum.YumBase):
repo = self.repos.getRepo(pkg.repoid)
remote = pkg.returnSimple('relativepath')
local = os.path.basename(remote)
local = os.path.join(self.opts.cachedir, local)
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.opts.quiet:
if not self.config.has_option('default', 'quiet'):
self.logger.info("%s already exists and appears to be complete" % local)
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.opts.quiet:
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.

View File

@ -19,35 +19,36 @@ import splittree
import shutil
class Pungi:
def __init__(self, opts):
self.opts = opts
def __init__(self, config):
self.config = config
self.prodpath = 'Fedora' # Probably should be defined elsewhere
self.topdir = os.path.join(self.opts.destdir, self.opts.version, self.opts.arch, 'os')
self.topdir = os.path.join(self.config.get('default', 'destdir'),
self.config.get('default', 'version'),
self.config.get('default', 'arch'),
'os')
def doBuildinstall(self):
# buildinstall looks for a comps file in base/ for now, copy it into place
os.makedirs(os.path.join(self.topdir, self.prodpath, 'base'))
shutil.copy(self.opts.comps, os.path.join(self.topdir, self.prodpath, 'base', 'comps.xml'))
args = '--product "Fedora" --version %s --release "%s" --prodpath %s %s' % (self.opts.version,
'Fedora %s' % self.opts.version, self.prodpath, self.topdir)
shutil.copy(self.config.get('default', 'comps'), os.path.join(self.topdir, self.prodpath, 'base', 'comps.xml'))
args = '--product "Fedora" --version %s --release "%s" --prodpath %s %s' % (self.config.get('default', 'version'),
'Fedora %s' % self.config.get('default', 'version'), self.prodpath, self.topdir)
os.system('/usr/lib/anaconda-runtime/buildinstall %s' % args)
def doPackageorder(self):
os.system('/usr/lib/anaconda-runtime/pkgorder %s %s %s > %s' % (self.topdir,
self.opts.arch,
self.prodpath,
os.path.join(self.opts.destdir, 'pkgorder-%s' % self.opts.arch)))
os.system('/usr/lib/anaconda-runtime/pkgorder %s %s %s > %s' % (self.topdir, self.config.get('default', 'arch'),
self.prodpath, os.path.join(self.config.get('default', 'destdir'), 'pkgorder-%s' % self.config.get('default', 'arch'))))
def doSplittree(self):
timber = splittree.Timber()
timber.arch = self.opts.arch
timber.total_discs = self.opts.discs
timber.bin_discs = self.opts.discs
timber.arch = self.config.get('default', 'arch')
timber.total_discs = self.config.getint('default', 'discs')
timber.bin_discs = self.config.getint('default', 'discs')
timber.src_discs = 0
timber.release_str = 'Fedora %s' % self.opts.version
timber.package_order_file = os.path.join(self.opts.destdir, 'pkgorder-%s' % self.opts.arch)
timber.release_str = 'Fedora %s' % self.config.get('default', 'version')
timber.package_order_file = os.path.join(self.config.get('default', 'destdir'), 'pkgorder-%s' % self.config.get('default', 'arch'))
timber.dist_dir = self.topdir
timber.src_dir = os.path.join(self.opts.destdir, self.opts.version, 'source', 'SRPMS')
timber.src_dir = os.path.join(self.config.get('default', 'destdir'), self.config.get('default', 'version'), 'source', 'SRPMS')
timber.product_path = self.prodpath
#timber.reserve_size =
@ -66,15 +67,18 @@ class Pungi:
discinfofile = os.path.join(self.topdir, '.discinfo') # we use this a fair amount
mkisofsargs = '-v -U -J -R -T -V' # common mkisofs flags
bootargs = ''
isodir = os.path.join(self.opts.destdir, self.opts.version, self.opts.arch, 'iso')
isodir = os.path.join(self.config.get('default', 'destdir'), self.config.get('default', 'version'),
self.config.get('default', 'arch'), 'iso')
os.makedirs(isodir)
for disc in range(1, self.opts.discs + 1): # cycle through the CD isos
volname = '"%s %s %s Disc %s"' % ('Fedora', self.opts.version, self.opts.arch, disc) # hacky :/
isoname = 'Fedora-%s-%s-disc%s.iso' % (self.opts.version, self.opts.arch, disc)
for disc in range(1, self.config.getint('default', 'discs') + 1): # cycle through the CD isos
volname = '"%s %s %s Disc %s"' % ('Fedora', self.config.get('default', 'version'),
self.config.get('default', 'arch'), disc) # hacky :/
isoname = 'Fedora-%s-%s-disc%s.iso' % (self.config.get('default', 'version'),
self.config.get('default', 'arch'), disc)
if disc == 1: # if this is the first disc, we want to set boot flags
if self.opts.arch == 'i386' or self.opts.arch == 'x86_64':
if self.config.get('default', 'arch') == 'i386' or self.config.get('default', 'arch') == 'x86_64':
bootargs = '-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table'
elif self.opts.arch == 'ppc':
elif self.config.get('default', 'arch') == 'ppc':
# Boy, it would be nice if somebody who understood ppc helped out here...
bootargs = ''
else:
@ -88,23 +92,25 @@ class Pungi:
os.path.join('%s-disc%s' % (self.topdir, disc))))
os.system('cd %s; sha1sum %s >> SHA1SUM' % (isodir, isoname))
if self.opts.discs > 1: # We've asked for more than one disc, make a DVD image
if self.config.getint('default', 'discs') > 1: # We've asked for more than one disc, make a DVD image
# backup the main .discinfo to use a split one. This is an ugly hack :/
content = open(discinfofile, 'r').readlines()
shutil.move(discinfofile, os.path.join(self.opts.destdir, '.discinfo-%s' % self.opts.arch))
content[content.index('ALL\n')] = ','.join([str(x) for x in range(1, self.opts.discs + 1)]) + '\n'
shutil.move(discinfofile, os.path.join(self.config.get('default', 'destdir'),
'.discinfo-%s' % self.config.get('default', 'arch')))
content[content.index('ALL\n')] = ','.join([str(x) for x in range(1, self.config.getint('default', 'discs') + 1)]) + '\n'
open(discinfofile, 'w').writelines(content)
# move the main repodata out of the way to use the split repodata
shutil.move(os.path.join(self.topdir, 'repodata'), os.path.join(self.opts.destdir, 'repodata-%s' % self.opts.arch))
shutil.move(os.path.join(self.topdir, 'repodata'), os.path.join(self.config.get('default', 'destdir'),
'repodata-%s' % self.config.get('default', 'arch')))
os.symlink('%s-disc1/repodata' % self.topdir, os.path.join(self.topdir, 'repodata'))
volname = '"%s %s %s DVD"' % ('Fedora', self.opts.version, self.opts.arch)
isoname = 'Fedora-%s-%s-DVD.iso' % (self.opts.version, self.opts.arch)
if self.opts.arch == 'i386' or self.opts.arch == 'x86_64':
volname = '"%s %s %s DVD"' % ('Fedora', self.config.get('default', 'version'), self.config.get('default', 'arch'))
isoname = 'Fedora-%s-%s-DVD.iso' % (self.config.get('default', 'version'), self.config.get('default', 'arch'))
if self.config.get('default', 'arch') == 'i386' or self.config.get('default', 'arch') == 'x86_64':
bootargs = '-b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table'
elif self.opts.arch == 'ppc':
elif self.config.get('default', 'arch') == 'ppc':
# Boy, it would be nice if somebody who understood ppc helped out here...
bootargs = ''
@ -116,10 +122,11 @@ class Pungi:
os.path.join('%s-disc1' % self.topdir)))
os.system('cd %s; sha1sum %s >> SHA1SUM' % (isodir, isoname))
shutil.move(os.path.join(self.opts.destdir, '.discinfo-%s' % self.opts.arch), discinfofile)
shutil.move(os.path.join(self.config.get('default', 'destdir'), '.discinfo-%s' % self.config.get('default', 'arch')), discinfofile)
os.unlink(os.path.join(self.topdir, 'repodata')) # remove our temp symlink and move the orig repodata back
shutil.move(os.path.join(self.opts.destdir, 'repodata-%s' % self.opts.arch), os.path.join(self.topdir, 'repodata'))
shutil.move(os.path.join(self.config.get('default', 'destdir'),
'repodata-%s' % self.config.get('default', 'arch')), os.path.join(self.topdir, 'repodata'))
def main():