[PATCH] Don't use OrderedDict.

Chris Lumens clumens at redhat.com
Tue Nov 12 19:29:15 UTC 2013


This doesn't exist in the python shipped with RHEL6, and pykickstart is
still being used on those systems for testing purposes.
---
 pykickstart/commands/autopart.py | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/pykickstart/commands/autopart.py b/pykickstart/commands/autopart.py
index 089788c..3f39793 100644
--- a/pykickstart/commands/autopart.py
+++ b/pykickstart/commands/autopart.py
@@ -21,8 +21,6 @@ from pykickstart.base import *
 from pykickstart.errors import *
 from pykickstart.options import *
 
-from collections import OrderedDict
-
 import gettext
 _ = lambda x: gettext.ldgettext("pykickstart", x)
 
@@ -215,28 +213,28 @@ 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)
-        # This uses OrderedDict because we want to always output --type=plain
-        # (as opposed to --type=partition) in __str__ when self.type is
-        # AUTOPART_TYPE_PLAIN.
-        self.typeMap = OrderedDict([("lvm", AUTOPART_TYPE_LVM),
-                                    ("btrfs", AUTOPART_TYPE_BTRFS),
-                                    ("plain", AUTOPART_TYPE_PLAIN),
-                                    ("partition", AUTOPART_TYPE_PLAIN)])
+        self.typeMap = { "lvm": AUTOPART_TYPE_LVM,
+                         "btrfs": AUTOPART_TYPE_BTRFS,
+                         "plain": AUTOPART_TYPE_PLAIN,
+                         "partition": AUTOPART_TYPE_PLAIN }
+
+    def _typeAsStr(self):
+        if self.type == AUTOPART_TYPE_LVM:
+            return "lvm"
+        elif self.type == AUTOPART_TYPE_BTRFS:
+            return "btrfs"
+        elif self.type == AUTOPART_TYPE_PLAIN:
+            return "plain"
 
     def __str__(self):
         retval = F16_AutoPart.__str__(self)
         if not self.autopart:
             return retval
 
-        if self.type is not None:
+        if self.type in self.typeMap.values():
             # remove any trailing newline
             retval = retval.strip()
-            retval += " --type="
-            for s, n in self.typeMap.items():
-                if self.type == n:
-                    retval += s
-                    break
-            retval += "\n"
+            retval += " --type=%s\n" % self._typeAsStr()
 
         return retval
 
@@ -301,6 +299,12 @@ class F20_AutoPart(F18_AutoPart):
         F18_AutoPart.__init__(self, writePriority=writePriority, *args, **kwargs)
         self.typeMap["thinp"] = AUTOPART_TYPE_LVM_THINP
 
+    def _typeAsStr(self):
+        if self.type == AUTOPART_TYPE_LVM_THINP:
+            return "thinp"
+        else:
+            return F18_AutoPart._typeAsStr(self)
+
     def parse(self, args):
         # call the overriden command to do it's job first
         retval = F18_AutoPart.parse(self, args)
-- 
1.8.3.1



More information about the anaconda-patches mailing list