[pykickstart][PATCH] Add --type option to autopart command.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



type can be one of the following: plain, lvm, btrfs
---
 pykickstart/commands/autopart.py |   54 ++++++++++++++++++++++++++++++++++++++
 pykickstart/constants.py         |    4 +++
 pykickstart/handlers/control.py  |    2 +-
 tests/commands/autopart.py       |   34 ++++++++++++++++++++---
 4 files changed, 88 insertions(+), 6 deletions(-)

diff --git a/pykickstart/commands/autopart.py b/pykickstart/commands/autopart.py
index c104380..910886f 100644
--- a/pykickstart/commands/autopart.py
+++ b/pykickstart/commands/autopart.py
@@ -145,3 +145,57 @@ class F16_AutoPart(F12_AutoPart):
         op.add_option("--nolvm", action="store_false", dest="lvm",
             default=True)
         return op
+
+class F17_AutoPart(F16_AutoPart):
+    def __init__(self, writePriority=100, *args, **kwargs):
+        F16_AutoPart.__init__(self, writePriority=writePriority, *args, **kwargs)
+        self.type = kwargs.get("type", None)
+        self.typeMap = { "lvm": AUTOPART_TYPE_LVM,
+                         "btrfs": AUTOPART_TYPE_BTRFS,
+                         "plain": AUTOPART_TYPE_PLAIN,
+                         "partition": AUTOPART_TYPE_PLAIN }
+
+    def __str__(self):
+        retval = F16_AutoPart.__str__(self)
+        if self.type is not None:
+            # remove any trailing newline
+            retval = retval.strip()
+            retval += " --type="
+            if self.type == AUTOPART_TYPE_LVM:
+                retval += "lvm"
+            elif self.type == AUTOPART_TYPE_BTRFS:
+                retval += "btrfs"
+            else:
+                retval += "plain"
+            retval += "\n"
+
+        return retval
+
+    def _getParser(self):
+        def type_cb(option, opt_str, value, parser):
+            if self.typeMap.has_key(value.lower()):
+                parser.values.ensure_value(option.dest,
+                                           self.typeMap[value.lower()])
+
+        def nolvm_cb(option, opt_str, value, parser):
+            parser.values.ensure_value(option.dest, AUTOPART_TYPE_PLAIN)
+
+        op = F16_AutoPart._getParser(self)
+        op.add_option("--nolvm", action="callback", callback=nolvm_cb,
+                      dest="type", nargs=0)
+
+        op.add_option("--type", action="callback", callback=type_cb,
+                      dest="type", nargs=1, type="string")
+        return op
+
+    def parse(self, args):
+        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
+        # Rely on any error handling from baseclass
+        F16_AutoPart.parse(self, extra)
+
+        self._setToSelf(self.op, opts)
+
+        # make this always True to avoid writing --nolvm
+        self.lvm = True
+
+        return self
diff --git a/pykickstart/constants.py b/pykickstart/constants.py
index 5e12fc8..d6fb9d4 100644
--- a/pykickstart/constants.py
+++ b/pykickstart/constants.py
@@ -21,6 +21,10 @@ CLEARPART_TYPE_LINUX = 0
 CLEARPART_TYPE_ALL = 1
 CLEARPART_TYPE_NONE = 2
 
+AUTOPART_TYPE_PLAIN = 0
+AUTOPART_TYPE_BTRFS = 1
+AUTOPART_TYPE_LVM = 2
+
 DISPLAY_MODE_CMDLINE = 0
 DISPLAY_MODE_GRAPHICAL = 1
 DISPLAY_MODE_TEXT = 2
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index 4a6ee8b..31385f7 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -827,7 +827,7 @@ commandMap = {
     F17: {
         "auth": authconfig.FC3_Authconfig,
         "authconfig": authconfig.FC3_Authconfig,
-        "autopart": autopart.F16_AutoPart,
+        "autopart": autopart.F17_AutoPart,
         "autostep": autostep.FC3_AutoStep,
         "bootloader": bootloader.F17_Bootloader,
         "btrfs": btrfs.F17_BTRFS,
diff --git a/tests/commands/autopart.py b/tests/commands/autopart.py
index 5949fea..a2b288a 100644
--- a/tests/commands/autopart.py
+++ b/tests/commands/autopart.py
@@ -84,15 +84,39 @@ class F16_TestCase(F12_TestCase):
         # Run F12 test case
         F12_TestCase.runTest(self)
 
+        if "--type" not in self.optionList:
+            # pass
+            self.assert_parse("autopart --nolvm",
+                              "autopart --nolvm\n")
+
+            # fail
+            self.assert_parse_error("autopart --nolvm=asdf")
+            self.assert_parse_error("autopart --nolvm True", KickstartValueError)
+            self.assert_parse_error("autopart --nolvm=1")
+            self.assert_parse_error("autopart --nolvm 0", KickstartValueError)
+
+class F17_TestCase(F16_TestCase):
+    def runTest(self):
+        # Run F16 test case
+        F16_TestCase.runTest(self)
+
         # pass
+        self.assert_parse("autopart --type=plain",
+                          "autopart --type=plain\n")
+        self.assert_parse("autopart --type=lvm",
+                          "autopart --type=lvm\n")
+        self.assert_parse("autopart --type=btrfs",
+                          "autopart --type=btrfs\n")
+
         self.assert_parse("autopart --nolvm",
-                          "autopart --nolvm\n")
+                          "autopart --type=plain\n")
+
+        # don't add --type= if none was specified
+        self.assert_parse("autopart",
+                          "autopart\n")
 
         # fail
-        self.assert_parse_error("autopart --nolvm=asdf")
-        self.assert_parse_error("autopart --nolvm True", KickstartValueError)
-        self.assert_parse_error("autopart --nolvm=1")
-        self.assert_parse_error("autopart --nolvm 0", KickstartValueError)
+        self.assert_parse_error("autopart --type")
 
 if __name__ == "__main__":
     unittest.main()
-- 
1.7.7

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux