[PATCH rhel7-branch] Provide syntax for specifying environments (#1061296).

Chris Lumens clumens at redhat.com
Tue Feb 4 16:43:00 UTC 2014


---
 pykickstart/parser.py    | 14 ++++++++++--
 tests/parser/packages.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/pykickstart/parser.py b/pykickstart/parser.py
index 170894d..d778eeb 100644
--- a/pykickstart/parser.py
+++ b/pykickstart/parser.py
@@ -263,6 +263,8 @@ class Packages(KickstartObject):
            addBase       -- Should the Base group be installed even if it is
                             not specified?
            default       -- Should the default package set be selected?
+           environment   -- What base environment should be selected?  Only one
+                            may be chosen at a time.
            excludedList  -- A list of all the packages marked for exclusion in
                             the %packages section, without the leading minus
                             symbol.
@@ -289,6 +291,7 @@ class Packages(KickstartObject):
 
         self.addBase = True
         self.default = False
+        self.environment = None
         self.excludedList = []
         self.excludedGroupList = []
         self.excludeDocs = False
@@ -304,6 +307,9 @@ class Packages(KickstartObject):
         pkgs = ""
 
         if not self.default:
+            if self.environment:
+                pkgs += "@^%s" % self.environment
+
             grps = self.groupList
             grps.sort()
             for grp in grps:
@@ -382,10 +388,14 @@ class Packages(KickstartObject):
         for pkg in pkgList:
             stripped = pkg.strip()
 
-            if stripped[0] == "@":
+            if stripped[0:2] == "@^":
+                self.environment = stripped[2:]
+            elif stripped[0] == "@":
                 self._processGroup(stripped[1:])
             elif stripped[0] == "-":
-                if stripped[1] == "@":
+                if stripped[1:3] == "@^" and self.environment == stripped[3:]:
+                    self.environment = None
+                elif stripped[1] == "@":
                     excludedGroupList.append(Group(name=stripped[2:]))
                 else:
                     newExcludedSet.add(stripped[1:])
diff --git a/tests/parser/packages.py b/tests/parser/packages.py
index be1d249..560a59f 100644
--- a/tests/parser/packages.py
+++ b/tests/parser/packages.py
@@ -51,5 +51,61 @@ bash
             self.parser.readKickstartFromString(self.ks)
             self.assertEqual(len(w), 0)
 
+class Packages_Contains_Environment_1_TestCase(ParserTest):
+    ks = """
+%packages
+@^whatever-environment
+%end
+"""
+
+    def runTest(self):
+        with warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter("always")
+            self.parser.readKickstartFromString(self.ks)
+            self.assertEqual(self.handler.packages.environment, "whatever-environment")
+
+class Packages_Contains_Environment_2_TestCase(ParserTest):
+    ks = """
+%packages
+@^whatever-environment
+@^another-environment
+%end
+"""
+
+    def runTest(self):
+        with warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter("always")
+            self.parser.readKickstartFromString(self.ks)
+            self.assertEqual(self.handler.packages.environment, "another-environment")
+
+class Packages_Contains_Environment_3_TestCase(ParserTest):
+    ks = """
+%packages
+@^whatever-environment
+-@^another-environment
+%end
+"""
+
+    def runTest(self):
+        with warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter("always")
+            self.parser.readKickstartFromString(self.ks)
+            self.assertEqual(self.handler.packages.environment, "whatever-environment")
+
+class Packages_Contains_Environment_4_TestCase(ParserTest):
+    ks = """
+%packages
+@^whatever-environment
+-@^whatever-environment
+@^another-environment
+%end
+"""
+
+    def runTest(self):
+        with warnings.catch_warnings(record=True) as w:
+            warnings.simplefilter("always")
+            self.parser.readKickstartFromString(self.ks)
+            self.assertEqual(self.handler.packages.environment, "another-environment")
+
 if __name__ == "__main__":
     unittest.main()
-- 
1.8.3.1



More information about the anaconda-patches mailing list