From 29303d0b2547c2da87a437c517267417d84581de Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Mon, 23 Apr 2012 18:31:22 -0400 Subject: [PATCH] allow for use of yum plugins during livecd creation https://bugzilla.redhat.com/show_bug.cgi?id=813429 This adds an option ("-p", or "--plugins") to livecd-creator to allow for the use of yum plugins during image creation. The initial usage case is for localized live images that want to use yum-langpacks when creating their live image so that they include the proper language packs for their locale. Aside from the noise of propagating the commandline options down to the yum instance, there is a bugfix where we re-call repository setup after we've actually added the repositories; this is required so that plugins operate properly. Bill --- imgcreate/creator.py | 10 ++++++---- imgcreate/live.py | 5 +++-- imgcreate/yuminst.py | 8 ++++++-- tools/livecd-creator | 5 +++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/imgcreate/creator.py b/imgcreate/creator.py index 35fe777..d8249cb 100644 --- a/imgcreate/creator.py +++ b/imgcreate/creator.py @@ -51,7 +51,7 @@ class ImageCreator(object): """ - def __init__(self, ks, name, releasever=None, tmpdir="/tmp"): + def __init__(self, ks, name, releasever=None, tmpdir="/tmp", useplugins=False): """Initialize an ImageCreator instance. ks -- a pykickstart.KickstartParser instance; this instance will be @@ -72,6 +72,7 @@ class ImageCreator(object): """A name for the image.""" self.releasever = releasever + self.useplugins = useplugins self.tmpdir = tmpdir """The directory in which all temporary files will be created.""" @@ -617,7 +618,7 @@ class ImageCreator(object): """ yum_conf = self._mktemp(prefix = "yum.conf-") - ayum = LiveCDYum(releasever=self.releasever) + ayum = LiveCDYum(releasever=self.releasever, useplugins=self.useplugins) ayum.setup(yum_conf, self._instroot) for repo in kickstart.get_repos(self.ks, repo_urls): @@ -632,6 +633,7 @@ class ImageCreator(object): yr.proxy = proxy if cost is not None: yr.cost = cost + ayum.setup(yum_conf, self._instroot) if kickstart.exclude_docs(self.ks): rpm.addMacro("_excludedocs", "1") @@ -778,7 +780,7 @@ class LoopImageCreator(ImageCreator): """ - def __init__(self, ks, name, fslabel=None, releasever=None, tmpdir="/tmp"): + def __init__(self, ks, name, fslabel=None, releasever=None, tmpdir="/tmp", useplugins=False): """Initialize a LoopImageCreator instance. This method takes the same arguments as ImageCreator.__init__() with @@ -787,7 +789,7 @@ class LoopImageCreator(ImageCreator): fslabel -- A string used as a label for any filesystems created. """ - ImageCreator.__init__(self, ks, name, releasever=releasever, tmpdir=tmpdir) + ImageCreator.__init__(self, ks, name, releasever=releasever, tmpdir=tmpdir, useplugins=useplugins) self.__fslabel = None self.fslabel = fslabel diff --git a/imgcreate/live.py b/imgcreate/live.py index d80f518..a73d7f0 100755 --- a/imgcreate/live.py +++ b/imgcreate/live.py @@ -40,7 +40,7 @@ class LiveImageCreatorBase(LoopImageCreator): """ def __init__(self, ks, name, fslabel=None, releasever=None, tmpdir="/tmp", - title="Linux", product="Linux"): + title="Linux", product="Linux", useplugins=False): """Initialise a LiveImageCreator instance. This method takes the same arguments as LoopImageCreator.__init__(). @@ -49,7 +49,8 @@ class LiveImageCreatorBase(LoopImageCreator): LoopImageCreator.__init__(self, ks, name, fslabel=fslabel, releasever=releasever, - tmpdir=tmpdir) + tmpdir=tmpdir, + useplugins=useplugins) self.compress_type = "xz" """mksquashfs compressor to use.""" diff --git a/imgcreate/yuminst.py b/imgcreate/yuminst.py index d835d9f..5605eea 100644 --- a/imgcreate/yuminst.py +++ b/imgcreate/yuminst.py @@ -45,12 +45,13 @@ class TextProgress(object): self.emit(logging.INFO, "...OK\n") class LiveCDYum(yum.YumBase): - def __init__(self, releasever=None): + def __init__(self, releasever=None, useplugins=False): """ releasever = optional value to use in replacing $releasever in repos """ yum.YumBase.__init__(self) self.releasever = releasever + self.useplugins = useplugins def doFileLogSetup(self, uid, logfile): # don't do the file log for the livecd as it can lead to open fds @@ -71,7 +72,10 @@ class LiveCDYum(yum.YumBase): conf = "[main]\n" conf += "installroot=%s\n" % installroot conf += "cachedir=/var/cache/yum\n" - conf += "plugins=0\n" + if self.useplugins: + conf += "plugins=1\n" + else: + conf += "plugins=0\n" conf += "reposdir=\n" conf += "failovermethod=priority\n" conf += "keepcache=1\n" diff --git a/tools/livecd-creator b/tools/livecd-creator index 6b2c799..8bb81aa 100755 --- a/tools/livecd-creator +++ b/tools/livecd-creator @@ -49,6 +49,9 @@ def parse_options(args): # Provided for img-create compatibility imgopt.add_option("-n", "--name", type="string", dest="fslabel", help=optparse.SUPPRESS_HELP) + imgopt.add_option("-p", "--plugins", action="store_true", dest="plugins", + help="Use yum plugins during image creation", + default=False) imgopt.add_option("", "--image-type", type="string", dest="image_type", help=optparse.SUPPRESS_HELP) imgopt.add_option("", "--compression-type", type="string", dest="compress_type", @@ -171,11 +174,13 @@ def main(): fslabel=fslabel, releasever=options.releasever, tmpdir=os.path.abspath(options.tmpdir), + useplugins=options.plugins, title=title, product=product) elif options.image_type == 'image': creator = imgcreate.LoopImageCreator(ks, name, fslabel=fslabel, releasever=options.releasever, + useplugins=options.plugins, tmpdir=os.path.abspath(options.tmpdir)) else: # Cannot happen, we validate this when parsing options. -- 2.11.4.GIT