In order to use the gather module outside of pungi itself, you need to pass it a valid config object. To make that easier, this patch moves the config object definition from pungi into pypungi.
Signed-off-by: Mark McLoughlin markmc@redhat.com
Index: pungi/pungi =================================================================== --- pungi.orig/pungi +++ pungi/pungi @@ -13,14 +13,13 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os +import pypungi.config import pypungi.gather import pypungi.pungi import yum import pykickstart.parser import pykickstart.version
-from ConfigParser import SafeConfigParser - def main():
# You must be this high to ride. @@ -28,54 +27,14 @@ def main(): print >> sys.stderr, "You must run pungi as root" return 1
- # Set some default variables, can be overrided in config file + config = pypungi.config.Config()
- # Turn this into a dict someday, to iterate over when setting defaults - osdir = "os" - sourcedir = "source" - debugdir = "debug" - isodir = "iso" - cdsize = "4608.0" - relnotefilere = "eula.txt fedora.css GPL README-BURNING-ISOS-en_US.txt RELEASE-NOTES-en_US.html ^RPM-GPG" - relnotedirre = "images stylesheet-images" - relnotepkgs = "fedora-release fedora-release-notes" - - (opts, args) = get_arguments() + (opts, args) = get_arguments(config)
# Set up the kickstart parser and pass in the kickstart file we were handed ksparser = pykickstart.parser.KickstartParser(pykickstart.version.makeVersion()) ksparser.readKickstart(opts.config)
- config = SafeConfigParser() - config.add_section('default') - - # add some sections here before setting stuff. - - # hard coded non-options - config.set('default', 'osdir', osdir) - config.set('default', 'sourcedir', sourcedir) - config.set('default', 'debugdir', debugdir) - config.set('default', 'isodir', isodir) - config.set('default', 'relnotefilere', relnotefilere) - config.set('default', 'relnotedirre', relnotedirre) - config.set('default', 'relnotepkgs', relnotepkgs) - config.set('default', 'product_path', 'Packages') - config.set('default', 'cachedir', '/var/cache/pungi') - config.set('default', 'arch', yum.rpmUtils.arch.getBaseArch()) - - # set configs from cli options - config.set('default', 'name', opts.name) - config.set('default', 'version', opts.ver) - config.set('default', 'flavor', opts.flavor) - config.set('default', 'destdir', opts.destdir) - config.set('default', 'cachedir', opts.cachedir) - config.set('default', 'bugurl', opts.bugurl) - config.set('default', 'discs', opts.discs) - - # set some other defaults - config.set('default', 'iso_basename', config.get('default', 'name')) - - config.set('default', 'cdsize', cdsize) for part in ksparser.handler.partition.partitions: if part.mountpoint == 'iso': config.set('default', 'cdsize', part.size) @@ -148,27 +107,34 @@ def main(): if __name__ == '__main__': from optparse import OptionParser import sys - import time - - today = time.strftime('%Y%m%d', time.localtime())
- def get_arguments(): + def get_arguments(config): parser = OptionParser(version="%prog 1.0.1")
+ def set_config(option, opt_str, value, parser, config): + config.set('default', option.dest, value) + # Pulled in from config file to be cli options as part of pykickstart conversion - parser.add_option("--name", default="Fedora", dest="name", + parser.add_option("--name", dest="name", type="string", + action="callback", callback=set_config, callback_args=(config, ), help='the name for your distribution (defaults to "Fedora")') - parser.add_option("--ver", default=today, dest="ver", + parser.add_option("--ver", dest="version", type="string", + action="callback", callback=set_config, callback_args=(config, ), help='the version of your distribution (defaults to datestamp)') - parser.add_option("--flavor", default="", dest="flavor", + parser.add_option("--flavor", dest="flavor", type="string", + action="callback", callback=set_config, callback_args=(config, ), help='the flavor of your distribution spin (optional)') - parser.add_option("--destdir", default=".", dest="destdir", + parser.add_option("--destdir", dest="destdir", type="string", + action="callback", callback=set_config, callback_args=(config, ), help='destination directory (defaults to current directory)') - parser.add_option("--cachedir", default="/var/cache/pungi", dest="cachedir", + parser.add_option("--cachedir", dest="cachedir", type="string", + action="callback", callback=set_config, callback_args=(config, ), help='package cache directory (defaults to /var/cache/pungi)') - parser.add_option("--bugurl", default="http://bugzilla.redhat.com", dest="bugurl", + parser.add_option("--bugurl", dest="bugurl", type="string", + action="callback", callback=set_config, callback_args=(config, ), help='the url for your bug system (defaults to http://bugzilla.redhat.com)') - parser.add_option("--discs", default='1', dest="discs", + parser.add_option("--discs", dest="discs", type="string", + action="callback", callback=set_config, callback_args=(config, ), help='the number of discs you want to create (defaults to 1)') parser.add_option("--nosource", action="store_true", dest="nosource", help='disable gathering of source packages (optional)') Index: pungi/pypungi/config.py =================================================================== --- /dev/null +++ pungi/pypungi/config.py @@ -0,0 +1,45 @@ +#!/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; version 2 of the License. +# +# 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. + +import time +import yum + +from ConfigParser import SafeConfigParser + +class Config(SafeConfigParser): + def __init__(self): + SafeConfigParser.__init__(self) + + self.add_section('default') + + self.set('default', 'osdir', 'os') + self.set('default', 'sourcedir', 'source') + self.set('default', 'debugdir', 'debug') + self.set('default', 'isodir', 'iso') + self.set('default', 'relnotefilere', + 'eula.txt fedora.css GPL README-BURNING-ISOS-en_US.txt RELEASE-NOTES-en_US.html ^RPM-GPG') + self.set('default', 'relnotedirre', 'images stylesheet-images') + self.set('default', 'relnotepkgs', 'fedora-release fedora-release-notes') + self.set('default', 'product_path', 'Packages') + self.set('default', 'cachedir', '/var/cache/pungi') + self.set('default', 'arch', yum.rpmUtils.arch.getBaseArch()) + self.set('default', 'name', 'Fedora') + self.set('default', 'iso_basename', 'Fedora') + self.set('default', 'version', time.strftime('%Y%m%d', time.localtime())) + self.set('default', 'flavor', '') + self.set('default', 'destdir', '.') + self.set('default', 'bugurl', 'http://bugzilla.redhat.com') + self.set('default', 'discs', '1') + self.set('default', 'cdsize', '4608.0') +
buildsys@lists.fedoraproject.org