Add --add-template{,-var}

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.

(cherry picked from commit 66359415be)

Resolves: rhbz#1157777
This commit is contained in:
Colin Walters 2014-05-01 21:34:54 -04:00 committed by Brian C. Lane
parent 923ec7f682
commit 1ef49fca1e
3 changed files with 31 additions and 4 deletions

View File

@ -142,7 +142,10 @@ class Lorax(BaseLoraxClass):
def run(self, ybo, product, version, release, variant="", bugurl="",
isfinal=False, workdir=None, outputdir=None, buildarch=None, volid=None,
domacboot=False, doupgrade=True, remove_temp=False):
domacboot=False, doupgrade=True, remove_temp=False,
size=2,
add_templates=None,
add_template_vars=None):
assert self._configured
@ -240,7 +243,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")

View File

@ -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=None,
add_template_vars=None):
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 or []
self.add_template_vars = add_template_vars or {}
self._runner.defaults = self.vars
def _install_branding(self):
@ -104,6 +108,8 @@ class RuntimeBuilder(object):
'''Install packages and do initial setup with runtime-install.tmpl'''
self._install_branding()
self._runner.run("runtime-install.tmpl")
for tmpl in self.add_templates:
self._runner.run(tmpl, **self.add_template_vars)
def writepkglists(self, pkglistdir):
'''debugging data: write out lists of package contents'''
@ -160,7 +166,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

View File

@ -133,6 +133,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)
@ -185,6 +191,13 @@ def main(args):
shutil.rmtree(tempdir)
sys.exit(1)
parsed_add_template_vars = {}
for kv in opts.add_template_vars:
k, t, v = kv.partition('=')
if t == '':
raise ValueError("Missing '=' for key=value in " % kv)
parsed_add_template_vars[k] = v
# run lorax
lorax = pylorax.Lorax()
lorax.configure(conf_file=opts.config)
@ -192,6 +205,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=parsed_add_template_vars,
remove_temp=True)