From 98ce9b66117682bb45befe90193a9d800067609c Mon Sep 17 00:00:00 2001
From: Colin Walters <walters@verbum.org>
Date: Tue, 25 Nov 2014 22:30:11 -0500
Subject: [PATCH] Add --includepkg argument

Recently, Fedora has been trying to do a 3 product split.  As part of
that, lorax was changed to do "installpkg lorax-product-*" via
provides.

I think that approach is awkward; a much simpler approach is to simply
specify the product package as input to lorax on the command line, via
external rel-eng scripts.

This patch therefore adds --includepkg (and we should probably add an
option to remove the implicit lorax-product-* glob).
---
 src/pylorax/__init__.py    | 2 ++
 src/pylorax/treebuilder.py | 5 +++++
 src/sbin/lorax             | 4 ++++
 3 files changed, 11 insertions(+)

diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py
index d4add39..8dc835e 100644
--- a/src/pylorax/__init__.py
+++ b/src/pylorax/__init__.py
@@ -152,6 +152,7 @@ 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,
+            includepkgs=[],
             size=2,
             add_templates=None,
             add_template_vars=None):
@@ -253,6 +254,7 @@ class Lorax(BaseLoraxClass):
         # NOTE: rb.root = ybo.conf.installroot (== self.inroot)
         rb = RuntimeBuilder(product=self.product, arch=self.arch,
                             yum=ybo, templatedir=templatedir,
+                            includepkgs=includepkgs,
                             add_templates=add_templates,
                             add_template_vars=add_template_vars)
 
diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py
index f10ea5b..4250cc7 100644
--- a/src/pylorax/treebuilder.py
+++ b/src/pylorax/treebuilder.py
@@ -68,6 +68,7 @@ def generate_module_info(moddir, outfile=None):
 class RuntimeBuilder(object):
     '''Builds the anaconda runtime image.'''
     def __init__(self, product, arch, yum, templatedir=None,
+                 includepkgs=[],
                  add_templates=None,
                  add_template_vars=None):
         root = yum.conf.installroot
@@ -81,6 +82,7 @@ class RuntimeBuilder(object):
                                            yum=yum, templatedir=templatedir)
         self.add_templates = add_templates or []
         self.add_template_vars = add_template_vars or {}
+        self._includepkgs = includepkgs
         self._runner.defaults = self.vars
 
     def _install_branding(self):
@@ -106,7 +108,10 @@ class RuntimeBuilder(object):
 
     def install(self):
         '''Install packages and do initial setup with runtime-install.tmpl'''
+        import sys
         self._install_branding()
+        if len(self._includepkgs) > 0:
+            self._runner.installpkg(*self._includepkgs)
         self._runner.run("runtime-install.tmpl")
         for tmpl in self.add_templates:
             self._runner.run(tmpl, **self.add_template_vars)
diff --git a/src/sbin/lorax b/src/sbin/lorax
index 8937c63..4aded08 100755
--- a/src/sbin/lorax
+++ b/src/sbin/lorax
@@ -119,6 +119,9 @@ def main(args):
     optional.add_option("-e", "--excludepkgs", default=[],
             action="append", metavar="STRING",
             help="package glob to exclude (may be listed multiple times)")
+    optional.add_option("-i", "--includepkgs", default=[],
+            action="append", metavar="STRING",
+            help="package glob to include")
     optional.add_option("--buildarch", default=None,
             help="build architecture", metavar="STRING")
     optional.add_option("--volid", default=None,
@@ -205,6 +208,7 @@ 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,
+              includepkgs=opts.includepkgs,
               add_templates=opts.add_templates,
               add_template_vars=parsed_add_template_vars,
               remove_temp=True)
-- 
1.8.3.1

