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:
parent
8bddcaef54
commit
95f6a0b642
12
config/pungi.conf
Normal file
12
config/pungi.conf
Normal 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
62
pungi
@ -17,31 +17,39 @@ import pypungi.gather
|
|||||||
import pypungi.pungi
|
import pypungi.pungi
|
||||||
import yum
|
import yum
|
||||||
|
|
||||||
|
from ConfigParser import SafeConfigParser
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# This is used for testing the module
|
|
||||||
(opts, args) = get_arguments()
|
(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:
|
try:
|
||||||
os.makedirs(opts.destdir)
|
os.makedirs(destdir)
|
||||||
except OSError, e:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
if not os.path.exists(opts.cachedir):
|
cachedir = config.get('default', 'cachedir')
|
||||||
|
|
||||||
|
if not os.path.exists(cachedir):
|
||||||
try:
|
try:
|
||||||
os.makedirs(opts.cachedir)
|
os.makedirs(cachedir)
|
||||||
except OSError, e:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
mygather = pypungi.gather.Gather(opts, pkglist)
|
mygather = pypungi.gather.Gather(config, pkglist)
|
||||||
mygather.getPackageObjects()
|
mygather.getPackageObjects()
|
||||||
mygather.downloadPackages()
|
mygather.downloadPackages()
|
||||||
|
|
||||||
mypungi = pypungi.pungi.Pungi(opts)
|
mypungi = pypungi.pungi.Pungi(config)
|
||||||
mypungi.doBuildinstall()
|
mypungi.doBuildinstall()
|
||||||
mypungi.doPackageorder()
|
mypungi.doPackageorder()
|
||||||
mypungi.doSplittree()
|
mypungi.doSplittree()
|
||||||
@ -57,22 +65,24 @@ if __name__ == '__main__':
|
|||||||
# hack job for now, I'm sure this could be better for our uses
|
# hack job for now, I'm sure this could be better for our uses
|
||||||
usage = "usage: %s [options]" % sys.argv[0]
|
usage = "usage: %s [options]" % sys.argv[0]
|
||||||
parser = OptionParser(usage=usage)
|
parser = OptionParser(usage=usage)
|
||||||
parser.add_option("--destdir", default=".", dest="destdir",
|
# parser.add_option("--destdir", default=".", dest="destdir",
|
||||||
help='destination directory (defaults to current directory)')
|
# help='destination directory (defaults to current directory)')
|
||||||
parser.add_option("--cachedir", default="./cache", dest="cachedir",
|
# parser.add_option("--cachedir", default="./cache", dest="cachedir",
|
||||||
help='cache directory (defaults to cache subdir of current directory)')
|
# help='cache directory (defaults to cache subdir of current directory)')
|
||||||
parser.add_option("--comps", default="comps.xml", dest="comps",
|
# parser.add_option("--comps", default="comps.xml", dest="comps",
|
||||||
help='comps file to use')
|
# help='comps file to use')
|
||||||
parser.add_option("--yumconf", default="yum.conf", dest="yumconf",
|
# parser.add_option("--yumconf", default="yum.conf", dest="yumconf",
|
||||||
help='yum config file to use')
|
# help='yum config file to use')
|
||||||
parser.add_option("--arch", default="i386", dest="arch",
|
# parser.add_option("--arch", default="i386", dest="arch",
|
||||||
help='Base arch to use')
|
# help='Base arch to use')
|
||||||
parser.add_option("--version", default="test", dest="version",
|
# parser.add_option("--version", default="test", dest="version",
|
||||||
help='Version of the spin')
|
# help='Version of the spin')
|
||||||
parser.add_option("--discs", default=5, type="int", dest="discs",
|
# parser.add_option("--discs", default=5, type="int", dest="discs",
|
||||||
help='Number of discs to spin')
|
# help='Number of discs to spin')
|
||||||
parser.add_option("-q", "--quiet", default=False, action="store_true",
|
# parser.add_option("-q", "--quiet", default=False, action="store_true",
|
||||||
help="Output as little as possible")
|
# help="Output as little as possible")
|
||||||
|
parser.add_option("-c", "--conf", default='/etc/pungi/pungi.conf', dest="config",
|
||||||
|
help='Config file to use')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,20 +17,20 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
class Gather(yum.YumBase):
|
class Gather(yum.YumBase):
|
||||||
def __init__(self, opts, pkglist):
|
def __init__(self, config, pkglist):
|
||||||
# Create a yum object to use
|
# Create a yum object to use
|
||||||
yum.YumBase.__init__(self)
|
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.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.cleanSqlite() # clean metadata that might be in the cache from previous runs
|
||||||
self.doRepoSetup()
|
self.doRepoSetup()
|
||||||
if opts.arch == 'i386':
|
if config.get('default', 'arch') == 'i386':
|
||||||
arches = yum.rpmUtils.arch.getArchList('i686')
|
arches = yum.rpmUtils.arch.getArchList('i686')
|
||||||
else:
|
else:
|
||||||
arches = yum.rpmUtils.arch.getArchList(opts.arch)
|
arches = yum.rpmUtils.arch.getArchList(config.get('default', 'arch'))
|
||||||
self.doSackSetup(arches)
|
self.doSackSetup(arches)
|
||||||
self.logger = yum.logging.getLogger("yum.verbose.pungi")
|
self.logger = yum.logging.getLogger("yum.verbose.pungi")
|
||||||
self.opts = opts
|
self.config = config
|
||||||
self.pkglist = pkglist
|
self.pkglist = pkglist
|
||||||
self.polist = []
|
self.polist = []
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class Gather(yum.YumBase):
|
|||||||
Returns the deps as a list"""
|
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))
|
self.logger.info('Checking deps of %s.%s' % (po.name, po.arch))
|
||||||
|
|
||||||
reqs = po.requires;
|
reqs = po.requires;
|
||||||
@ -74,7 +74,7 @@ class Gather(yum.YumBase):
|
|||||||
for match in matches:
|
for match in matches:
|
||||||
unprocessed_pkgs[match] = None
|
unprocessed_pkgs[match] = None
|
||||||
|
|
||||||
if not self.opts.quiet:
|
if not self.config.has_option('default', 'quiet'):
|
||||||
for pkg in unprocessed_pkgs.keys():
|
for pkg in unprocessed_pkgs.keys():
|
||||||
self.logger.info('Found %s.%s' % (pkg.name, pkg.arch))
|
self.logger.info('Found %s.%s' % (pkg.name, pkg.arch))
|
||||||
|
|
||||||
@ -100,14 +100,17 @@ class Gather(yum.YumBase):
|
|||||||
download them from their respective repos."""
|
download them from their respective repos."""
|
||||||
|
|
||||||
|
|
||||||
if not self.opts.quiet:
|
if not self.config.has_option('default', 'quiet'):
|
||||||
downloads = []
|
downloads = []
|
||||||
for pkg in self.polist:
|
for pkg in self.polist:
|
||||||
downloads.append('%s.%s' % (pkg.name, pkg.arch))
|
downloads.append('%s.%s' % (pkg.name, pkg.arch))
|
||||||
downloads.sort()
|
downloads.sort()
|
||||||
self.logger.info("Download list: %s" % downloads)
|
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):
|
if not os.path.exists(pkgdir):
|
||||||
os.makedirs(pkgdir)
|
os.makedirs(pkgdir)
|
||||||
|
|
||||||
@ -115,18 +118,18 @@ class Gather(yum.YumBase):
|
|||||||
repo = self.repos.getRepo(pkg.repoid)
|
repo = self.repos.getRepo(pkg.repoid)
|
||||||
remote = pkg.returnSimple('relativepath')
|
remote = pkg.returnSimple('relativepath')
|
||||||
local = os.path.basename(remote)
|
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
|
if (os.path.exists(local) and
|
||||||
str(os.path.getsize(local)) == pkg.returnSimple('packagesize')):
|
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)
|
self.logger.info("%s already exists and appears to be complete" % local)
|
||||||
os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
|
os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Disable cache otherwise things won't download
|
# Disable cache otherwise things won't download
|
||||||
repo.cache = 0
|
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))
|
self.logger.info('Downloading %s' % os.path.basename(remote))
|
||||||
pkg.localpath = local # Hack: to set the localpath to what we want.
|
pkg.localpath = local # Hack: to set the localpath to what we want.
|
||||||
|
|
||||||
|
@ -19,35 +19,36 @@ import splittree
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
class Pungi:
|
class Pungi:
|
||||||
def __init__(self, opts):
|
def __init__(self, config):
|
||||||
self.opts = opts
|
self.config = config
|
||||||
self.prodpath = 'Fedora' # Probably should be defined elsewhere
|
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):
|
def doBuildinstall(self):
|
||||||
# buildinstall looks for a comps file in base/ for now, copy it into place
|
# buildinstall looks for a comps file in base/ for now, copy it into place
|
||||||
os.makedirs(os.path.join(self.topdir, self.prodpath, 'base'))
|
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'))
|
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.opts.version,
|
args = '--product "Fedora" --version %s --release "%s" --prodpath %s %s' % (self.config.get('default', 'version'),
|
||||||
'Fedora %s' % self.opts.version, self.prodpath, self.topdir)
|
'Fedora %s' % self.config.get('default', 'version'), self.prodpath, self.topdir)
|
||||||
os.system('/usr/lib/anaconda-runtime/buildinstall %s' % args)
|
os.system('/usr/lib/anaconda-runtime/buildinstall %s' % args)
|
||||||
|
|
||||||
def doPackageorder(self):
|
def doPackageorder(self):
|
||||||
os.system('/usr/lib/anaconda-runtime/pkgorder %s %s %s > %s' % (self.topdir,
|
os.system('/usr/lib/anaconda-runtime/pkgorder %s %s %s > %s' % (self.topdir, self.config.get('default', 'arch'),
|
||||||
self.opts.arch,
|
self.prodpath, os.path.join(self.config.get('default', 'destdir'), 'pkgorder-%s' % self.config.get('default', 'arch'))))
|
||||||
self.prodpath,
|
|
||||||
os.path.join(self.opts.destdir, 'pkgorder-%s' % self.opts.arch)))
|
|
||||||
|
|
||||||
def doSplittree(self):
|
def doSplittree(self):
|
||||||
timber = splittree.Timber()
|
timber = splittree.Timber()
|
||||||
timber.arch = self.opts.arch
|
timber.arch = self.config.get('default', 'arch')
|
||||||
timber.total_discs = self.opts.discs
|
timber.total_discs = self.config.getint('default', 'discs')
|
||||||
timber.bin_discs = self.opts.discs
|
timber.bin_discs = self.config.getint('default', 'discs')
|
||||||
timber.src_discs = 0
|
timber.src_discs = 0
|
||||||
timber.release_str = 'Fedora %s' % self.opts.version
|
timber.release_str = 'Fedora %s' % self.config.get('default', 'version')
|
||||||
timber.package_order_file = os.path.join(self.opts.destdir, 'pkgorder-%s' % self.opts.arch)
|
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.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.product_path = self.prodpath
|
||||||
#timber.reserve_size =
|
#timber.reserve_size =
|
||||||
|
|
||||||
@ -66,15 +67,18 @@ class Pungi:
|
|||||||
discinfofile = os.path.join(self.topdir, '.discinfo') # we use this a fair amount
|
discinfofile = os.path.join(self.topdir, '.discinfo') # we use this a fair amount
|
||||||
mkisofsargs = '-v -U -J -R -T -V' # common mkisofs flags
|
mkisofsargs = '-v -U -J -R -T -V' # common mkisofs flags
|
||||||
bootargs = ''
|
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)
|
os.makedirs(isodir)
|
||||||
for disc in range(1, self.opts.discs + 1): # cycle through the CD isos
|
for disc in range(1, self.config.getint('default', 'discs') + 1): # cycle through the CD isos
|
||||||
volname = '"%s %s %s Disc %s"' % ('Fedora', self.opts.version, self.opts.arch, disc) # hacky :/
|
volname = '"%s %s %s Disc %s"' % ('Fedora', self.config.get('default', 'version'),
|
||||||
isoname = 'Fedora-%s-%s-disc%s.iso' % (self.opts.version, self.opts.arch, disc)
|
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 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'
|
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...
|
# Boy, it would be nice if somebody who understood ppc helped out here...
|
||||||
bootargs = ''
|
bootargs = ''
|
||||||
else:
|
else:
|
||||||
@ -88,23 +92,25 @@ class Pungi:
|
|||||||
os.path.join('%s-disc%s' % (self.topdir, disc))))
|
os.path.join('%s-disc%s' % (self.topdir, disc))))
|
||||||
os.system('cd %s; sha1sum %s >> SHA1SUM' % (isodir, isoname))
|
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 :/
|
# backup the main .discinfo to use a split one. This is an ugly hack :/
|
||||||
content = open(discinfofile, 'r').readlines()
|
content = open(discinfofile, 'r').readlines()
|
||||||
shutil.move(discinfofile, os.path.join(self.opts.destdir, '.discinfo-%s' % self.opts.arch))
|
shutil.move(discinfofile, os.path.join(self.config.get('default', 'destdir'),
|
||||||
content[content.index('ALL\n')] = ','.join([str(x) for x in range(1, self.opts.discs + 1)]) + '\n'
|
'.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)
|
open(discinfofile, 'w').writelines(content)
|
||||||
|
|
||||||
|
|
||||||
# move the main repodata out of the way to use the split repodata
|
# 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'))
|
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)
|
volname = '"%s %s %s DVD"' % ('Fedora', self.config.get('default', 'version'), self.config.get('default', 'arch'))
|
||||||
isoname = 'Fedora-%s-%s-DVD.iso' % (self.opts.version, self.opts.arch)
|
isoname = 'Fedora-%s-%s-DVD.iso' % (self.config.get('default', 'version'), self.config.get('default', 'arch'))
|
||||||
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'
|
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...
|
# Boy, it would be nice if somebody who understood ppc helped out here...
|
||||||
bootargs = ''
|
bootargs = ''
|
||||||
|
|
||||||
@ -116,10 +122,11 @@ class Pungi:
|
|||||||
os.path.join('%s-disc1' % self.topdir)))
|
os.path.join('%s-disc1' % self.topdir)))
|
||||||
os.system('cd %s; sha1sum %s >> SHA1SUM' % (isodir, isoname))
|
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
|
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():
|
def main():
|
||||||
|
Loading…
Reference in New Issue
Block a user