From 38ff3cef533284b0d631091c5c9c6f529230f09c Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Sun, 26 Aug 2007 14:08:27 -0400 Subject: [PATCH] - Pass gather a ksparser object instead, needed for yum repos and more advanced package handling. - Use ksparser to get repo(s) from kickstart config. - Don't rely upon a yum conf, do all setup ourselves. --- Changelog | 4 +++ pungi | 12 +++++--- pypungi/gather.py | 71 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 64 insertions(+), 23 deletions(-) diff --git a/Changelog b/Changelog index 0a2639f0..e8fd8a2f 100644 --- a/Changelog +++ b/Changelog @@ -3,6 +3,10 @@ - Turn pkglist into a pre-parsed package dictionary - Arrange config setting logically - Error out on usage if no config file passed +- Pass gather a ksparser object instead, needed for yum repos + and more advanced package handling. +- Use ksparser to get repo(s) from kickstart config. +- Don't rely upon a yum conf, do all setup ourselves. * Fri Aug 24 2007 Jesse Keating - Remove a lot of configurable items and hard set them diff --git a/pungi b/pungi index d76dcead..82936d4a 100755 --- a/pungi +++ b/pungi @@ -41,6 +41,7 @@ def main(): ksparser.readKickstart(opts.config) config = SafeConfigParser() + config.add_section('default') # add some sections here before setting stuff. @@ -53,6 +54,7 @@ def main(): config.set('default', 'relnotedirre', relnotedirre) config.set('default', 'relnotepkgs', relnotepkgs) config.set('default', 'product_path', 'Packages') + config.set('default', 'cachedir', '/srv/pungi/cache') # needs to be handled better # set configs from cli options config.set('default', 'name', opts.name) @@ -88,7 +90,7 @@ def main(): sys.exit(1) # Actually do work. - if not config.get('default', 'arch') == 'source': + if not opts.sourceisos: if opts.do_all or opts.do_gather: mygather = pypungi.gather.Gather(config, ksparser) mygather.getPackageObjects() @@ -160,6 +162,8 @@ if __name__ == '__main__': help='the number of discs you want to create (defaults to 1)') parser.add_option("--nosource", action="store_true", dest="nosource", help='the flavor of your distribution spin (optional)') + parser.add_option("--sourceisos", default=False, action="store_true", dest="sourceisos", + help='Create the source isos (other arch runs must be done)') parser.add_option("-c", "--config", dest="config", help='Path to kickstart config file') @@ -181,9 +185,9 @@ if __name__ == '__main__': (opts, args) = parser.parse_args() - if not '-c' in sys.argv or not '--config' in sys.argv: - parser.print_help() - sys.exit(0) + #if not '-c' in sys.argv or not '--config' in sys.argv: + # parser.print_help() + # sys.exit(0) if opts.do_gather or opts.do_createrepo or opts.do_buildinstall or opts.do_packageorder or opts.do_splittree or opts.do_createiso: opts.do_all = False diff --git a/pypungi/gather.py b/pypungi/gather.py index 067adfef..ba2fb06d 100755 --- a/pypungi/gather.py +++ b/pypungi/gather.py @@ -48,8 +48,23 @@ class PungiYum(yum.YumBase): class Gather(pypungi.PungiBase): def __init__(self, config, ksparser): - pypungi.PungiBase.__init__(self, config) + # Set up arches, needed for log file name + hostarch = os.uname()[4] + if hostarch in yum.rpmUtils.arch.getArchList('athlon'): + config.set('default', 'arch', 'i386') + yumarch = 'athlon' + elif hostarch == 'ppc': + config.set('default', 'arch', 'ppc') + yumarch = 'ppc64' + elif hostarch == 'sparc': + config.set('default', 'arch', 'sparc') + yumarch = 'sparc64v' + else: + config.set('default', 'arch', hostarch) + yumarch = hostarch + pypungi.PungiBase.__init__(self, config) + # Set our own logging name space self.logger = logging.getLogger('Pungi.Gather') @@ -61,32 +76,50 @@ class Gather(pypungi.PungiBase): self.logger.addHandler(console) self.ksparser = ksparser - self.config.cachedir = os.path.join(self.workdir, 'yumcache') self.polist = [] self.srpmlist = [] self.resolved_deps = {} # list the deps we've already resolved, short circuit. # Create a yum object to use self.ayum = PungiYum(config) - self.ayum.doConfigSetup(fn=config.get('default', 'yumconf'), debuglevel=6, errorlevel=6, root=os.path.join(self.workdir, 'yumroot')) + self.ayum.doLoggingSetup(6, 6) + yumconf = yum.config.YumConf() + yumconf.debuglevel = 6 + yumconf.errorlevel = 6 + yumconf.cachedir = os.path.join(self.workdir, 'yumcache') + yumconf.persistdir = os.path.join(self.workdir, 'yumlib') + yumconf.installroot = os.path.join(self.workdir, 'yumroot') + yumconf.uid = os.geteuid() + yumconf.cache = 0 + self.ayum._conf = yumconf + self.ayum.repos.setCacheDir(self.ayum.conf.cachedir) + self.ayum.cleanMetadata() # clean metadata that might be in the cache from previous runs self.ayum.cleanSqlite() # clean metadata that might be in the cache from previous runs - self.ayum.doRepoSetup() - self.ayum.doTsSetup() - self.ayum.doRpmDBSetup() - if config.get('default', 'arch') == 'i386': - arches = yum.rpmUtils.arch.getArchList('i686') - self.ayum.compatarch = 'i686' - elif config.get('default', 'arch') == 'ppc': - arches = yum.rpmUtils.arch.getArchList('ppc64') - self.ayum.compatarch = 'ppc64' - elif config.get('default', 'arch') == 'sparc': - arches = yum.rpmUtils.arch.getArchList('sparc64v') - self.ayum.compatarch = 'sparc64v' - else: - arches = yum.rpmUtils.arch.getArchList(config.get('default', 'arch')) - self.ayum.compatarch = config.get('default', 'arch') + self.ayum.compatarch = yumarch + arches = yum.rpmUtils.arch.getArchList(yumarch) arches.append('src') # throw source in there, filter it later + + # deal with our repos + for repo in ksparser.handler.repo.repoList: + self.logger.info('Adding repo %s' % repo.name) + thisrepo = yum.yumRepo.YumRepository(repo.name) + thisrepo.name = repo.name + # add excludes and such here when pykickstart gets them + if repo.mirrorlist: + thisrepo.mirrorlist = repo.mirrorlist + self.logger.info('URI for repo %s is %s' % (repo.name, repo.mirrorlist)) + else: + thisrepo.baseurl = repo.baseurl + self.logger.info('URI for repo %s is %s' % (repo.name, repo.baseurl)) + self.ayum._repos.add(thisrepo) + + for repo in self.ayum.repos.repos.values(): + self.logger.info('Enabling repo %s' % repo.name) + repo.enable() + repo.enablegroups = True + + self.logger.info('Getting sacks for arches %s' % arches) self.ayum._getSacks(archlist=arches) def _filtersrc(self, po): @@ -210,7 +243,7 @@ class Gather(pypungi.PungiBase): matchdict = {} # A dict of objects to names # Build up a package dict. - pkgdict = {'groups': [], 'packages': [], 'excludes': []) + pkgdict = {'groups': [], 'packages': [], 'excludes': []} for group in self.ksparser.handler.packages.groupList: if group.include == 1: pkgdict['groups'].append(group.name)