From 854899344ceab0ff8bb5dbc65882bc5279a8865f Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 15 Jan 2013 08:05:04 -0500 Subject: [PATCH] Implement %fulltree-excludes kickstart section to exclude packages from --fulltree processing. --- src/bin/pungi.py | 6 ++--- src/pypungi/__init__.py | 7 ++++-- src/pypungi/ks.py | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 src/pypungi/ks.py diff --git a/src/bin/pungi.py b/src/bin/pungi.py index c1e71bc0..7dbd9fcf 100755 --- a/src/bin/pungi.py +++ b/src/bin/pungi.py @@ -15,8 +15,7 @@ import os import pypungi import pypungi.config -import pykickstart.parser -import pykickstart.version +import pypungi.ks import subprocess def main(): @@ -42,8 +41,7 @@ def main(): pass # 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) + ksparser = pypungi.ks.get_ksparser(ks_path=opts.config) if opts.sourceisos: config.set('pungi', 'arch', 'source') diff --git a/src/pypungi/__init__.py b/src/pypungi/__init__.py index e811b9d5..d5a9440a 100644 --- a/src/pypungi/__init__.py +++ b/src/pypungi/__init__.py @@ -223,6 +223,8 @@ class Pungi(pypungi.PungiBase): self.is_greedy = self.config.getboolean("pungi", "alldeps") self.is_resolve_deps = True # TODO: implement --nodepsolve + self.fulltree_excludes = set(self.ksparser.handler.fulltree_excludes) + def _add_yum_repo(self, name, url, mirrorlist=False, groups=True, cost=1000, includepkgs=None, excludepkgs=None, proxy=None): @@ -682,7 +684,7 @@ class Pungi(pypungi.PungiBase): packages_by_name.setdefault(po.name, []).append(po) for name, packages in packages_by_name.iteritems(): - packages = self.excludePackages(packages) + packages = self.excludePackages(packages or []) if self.is_greedy: packages = yum.packageSack.ListPackageSack(packages).returnNewestByNameArch() else: @@ -810,7 +812,8 @@ class Pungi(pypungi.PungiBase): for srpm_po in srpm_po_list: if srpm_po in self.completed_fulltree: continue - srpms.append(srpm_po) + if srpm_po.name not in self.fulltree_excludes: + srpms.append(srpm_po) self.completed_fulltree.add(srpm_po) added = set() diff --git a/src/pypungi/ks.py b/src/pypungi/ks.py new file mode 100644 index 00000000..8fe8b31c --- /dev/null +++ b/src/pypungi/ks.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + + +""" +Kickstart syntax is extended with: + +%fulltree-excludes + + +... +%end + +Fulltree excludes allow us to define SRPM names +we don't want to be part of fulltree processing. +""" + + +import pykickstart.parser +import pykickstart.sections + + +class FulltreeExcludesSection(pykickstart.sections.Section): + sectionOpen = "%fulltree-excludes" + + def handleLine(self, line): + if not self.handler: + return + + (h, s, t) = line.partition('#') + line = h.rstrip() + + self.handler.fulltree_excludes.add(line) + + +class KickstartParser(pykickstart.parser.KickstartParser): + def setupSections(self): + pykickstart.parser.KickstartParser.setupSections(self) + self.registerSection(FulltreeExcludesSection(self.handler)) + + +HandlerClass = pykickstart.version.returnClassForVersion() +class PungiHandler(HandlerClass): + def __init__(self, *args, **kwargs): + HandlerClass.__init__(self, *args, **kwargs) + self.fulltree_excludes = set() + + +def get_ksparser(ks_path=None): + """ + Return a kickstart parser instance. + Read kickstart if ks_path provided. + """ + ksparser = KickstartParser(PungiHandler()) + if ks_path: + ksparser.readKickstart(ks_path) + return ksparser