lorax: [PATCH] Add --add-template{,-var}

Colin Walters walters at verbum.org
Sun May 11 21:35:56 UTC 2014


[ Also attached is the template I used to make an rpm-ostree installer ]

What I need is to make something like the traditional DVD which also
includes packages. At present this is apparently handled by the
entirely separate pungi tool.

At the moment for me, it's the least bad option to modify lorax to
inject data from an external source than to create a new tool, or
attempt to also modify pungi to do this.

This would also allow pungi's DVD creation to eventually be a set of
external templates for Lorax.
---
 src/pylorax/__init__.py | 9 +++++++--
 src/pylorax/treebuilder.py | 18 ++++++++++++++++--
 src/sbin/lorax | 8 ++++++++
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py
index 7d94783..8c1d631 100644
--- a/src/pylorax/__init__.py
+++ b/src/pylorax/__init__.py
@@ -151,7 +151,10 @@ class Lorax(BaseLoraxClass):
 
     def run(self, ybo, product, version, release, variant="", 
bugurl="",
             isfinal=False, workdir=None, outputdir=None, 
buildarch=None, volid=None,
- domacboot=True, doupgrade=True, remove_temp=False, size=2):
+ domacboot=True, doupgrade=True, remove_temp=False,
+ add_templates=[],
+ add_template_vars=[],
+ size=2):
 
         assert self._configured
 
@@ -249,7 +252,9 @@ class Lorax(BaseLoraxClass):
         templatedir = self.conf.get("lorax", "sharedir")
         # NOTE: rb.root = ybo.conf.installroot (== self.inroot)
         rb = RuntimeBuilder(product=self.product, arch=self.arch,
- yum=ybo, templatedir=templatedir)
+ yum=ybo, templatedir=templatedir,
+ add_templates=add_templates,
+ add_template_vars=add_template_vars)
 
         logger.info("installing runtime packages")
         rb.yum.conf.skip_broken = self.conf.getboolean("yum", 
"skipbroken")
diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py
index 1b71604..771fdcd 100644
--- a/src/pylorax/treebuilder.py
+++ b/src/pylorax/treebuilder.py
@@ -67,7 +67,9 @@ def generate_module_info(moddir, outfile=None):
 
 class RuntimeBuilder(object):
     '''Builds the anaconda runtime image.'''
- def __init__(self, product, arch, yum, templatedir=None):
+ def __init__(self, product, arch, yum, templatedir=None,
+ add_templates=[],
+ add_template_vars=[]):
         root = yum.conf.installroot
         # use a copy of product so we can modify it locally
         product = product.copy()
@@ -77,6 +79,8 @@ class RuntimeBuilder(object):
         self.yum = yum
         self._runner = LoraxTemplateRunner(inroot=root, outroot=root,
                                            yum=yum, 
templatedir=templatedir)
+ self.add_templates = add_templates
+ self.add_template_vars = add_template_vars
         self._runner.defaults = self.vars
 
     def _install_branding(self):
@@ -104,6 +108,15 @@ class RuntimeBuilder(object):
         '''Install packages and do initial setup with 
runtime-install.tmpl'''
         self._install_branding()
         self._runner.run("runtime-install.tmpl")
+ addvars = {}
+ for kv in self.add_template_vars:
+ vals = kv.split('=', 1)
+ if len(vals) <= 1:
+ raise ValueError("Template variables must be of the form key=value")
+ (k,v) = vals
+ addvars[k] = v
+ for tmpl in self.add_templates:
+ self._runner.run(tmpl, **addvars)
 
     def writepkglists(self, pkglistdir):
         '''debugging data: write out lists of package contents'''
@@ -161,7 +174,8 @@ class RuntimeBuilder(object):
         # Reset selinux context on new rootfs
         with imgutils.LoopDev( joinpaths(workdir, "LiveOS/rootfs.img") 
) as loopdev:
             with imgutils.Mount(loopdev) as mnt:
- cmd = [ "setfiles", "-e", "/proc", "-e", "/sys", "-e", "/dev", 
"/etc/selinux/targeted/contexts/files/file_contexts", "/"]
+ cmd = [ "setfiles", "-e", "/proc", "-e", "/sys", "-e", "/dev", "-e", 
"/install",
+ "/etc/selinux/targeted/contexts/files/file_contexts", "/"]
                 runcmd(cmd, root=mnt)
 
         # squash the live rootfs and clean up workdir
diff --git a/src/sbin/lorax b/src/sbin/lorax
index 4a9cde5..bfb90a5 100755
--- a/src/sbin/lorax
+++ b/src/sbin/lorax
@@ -134,6 +134,12 @@ def main(args):
             help="Path to logfile")
     optional.add_option("--tmp", default="/var/tmp",
             help="Top level temporary directory" )
+ optional.add_option("--add-template", dest="add_templates",
+ action="append", help="Additional template to execute",
+ default=[])
+ optional.add_option("--add-template-var", dest="add_template_vars",
+ action="append", help="Set variable for additional templates",
+ default=[])
 
     # add the option groups to the parser
     parser.add_option_group(required)
@@ -193,6 +199,8 @@ def main(args):
               opts.variant, opts.bugurl, opts.isfinal,
               workdir=tempdir, outputdir=outputdir, 
buildarch=opts.buildarch,
               volid=opts.volid, domacboot=opts.domacboot, 
doupgrade=opts.doupgrade,
+ add_templates=opts.add_templates,
+ add_template_vars=opts.add_template_vars,
               remove_temp=True)
 
 
-- 
1.8.3.1



-------------- next part --------------
A non-text attachment was scrubbed...
Name: lorax-embed-repo.tmpl
Type: text/x-matlab
Size: 552 bytes
Desc: not available
URL: <https://lists.fedorahosted.org/pipermail/anaconda-patches/attachments/20140511/b32a43c6/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-add-template-var.patch
Type: text/x-patch
Size: 5577 bytes
Desc: not available
URL: <https://lists.fedorahosted.org/pipermail/anaconda-patches/attachments/20140511/b32a43c6/attachment-0003.bin>


More information about the anaconda-patches mailing list