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

Re: [PATCH] Add --root-device to upgrade command



Chris Lumens wrote:
+    def _getParser(self):
+        op = KSOptionParser(lineno=self.lineno)
+        op.add_option("--root-device", dest="root_device")
+        return op

Instead of calling KSOptionParser, call FC3_Upgrade._getParser(self)
here to pull in whatever arguments FC3_Upgrade's KSOptionParser object
may support.  I know it's none in this case, but that's how it works in
every other class in pykickstart and I really like things to be
consistent.


See F9_Autopart vs. FC3_Autopart. Same case as with upgrades. The base class doesn't define _getParser and the derived class calls KSOptionParser directly instead of calling _getParser from the base class. This will break when the base class doesn't define _getParser.

Attached patch with all other issues resolved except the _getParser change.

--
Alexander.
 pykickstart/commands/upgrade.py |   36 ++++++++++++++++++++++++++++++++++++
 pykickstart/handlers/control.py |    4 ++--
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/pykickstart/commands/upgrade.py b/pykickstart/commands/upgrade.py
index b7dba86..8a642d0 100644
--- a/pykickstart/commands/upgrade.py
+++ b/pykickstart/commands/upgrade.py
@@ -49,3 +49,39 @@ class FC3_Upgrade(KickstartCommand):
            self.upgrade = True
         else:
            self.upgrade = False
+
+class F11_Upgrade(FC3_Upgrade):
+    removedKeywords = FC3_Upgrade.removedKeywords
+    removedAttrs = FC3_Upgrade.removedAttrs
+
+    def __init__(self, writePriority=0, *args, **kwargs):
+        FC3_Upgrade.__init__(self, writePriority, *args, **kwargs)
+
+        self.op = self._getParser()
+        self.root_device = kwargs.get("root_device", None)
+
+    def __str__(self):
+        if self.upgrade and (self.root_device is not None):
+            retval="# Upgrade existing installation\nupgrade --root-device=%s\n" % self.root_device
+        else:
+            retval=FC3_Upgrade.__str__(self)
+
+        return retval
+
+    def _getParser(self):
+        op = KSOptionParser(lineno=self.lineno)
+        op.add_option("--root-device", dest="root_device")
+        return op
+
+    def parse(self, args):
+        (opts, extra) = self.op.parse_args(args=args)
+
+        if (opts.root_device is not None) and (opts.root_device == ""):
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not accept empty parameter %s") % ("upgrade", "--root-device"))
+        else:
+            self.root_device = opts.root_device
+
+        if self.currentCmd == "upgrade":
+           self.upgrade = True
+        else:
+           self.upgrade = False
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index 459d3a8..961176a 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -488,7 +488,7 @@ commandMap = {
         "halt": reboot.FC6_Reboot,
         "harddrive": method.FC6_Method,
         "ignoredisk": ignoredisk.F8_IgnoreDisk,
-        "install": upgrade.FC3_Upgrade,
+        "install": upgrade.F11_Upgrade,
         "interactive": interactive.FC3_Interactive,
         "iscsi": iscsi.F10_Iscsi,
         "iscsiname": iscsiname.FC6_IscsiName,
@@ -517,7 +517,7 @@ commandMap = {
         "text": displaymode.FC3_DisplayMode,
         "timezone": timezone.FC6_Timezone,
         "updates": updates.F7_Updates,
-        "upgrade": upgrade.FC3_Upgrade,
+        "upgrade": upgrade.F11_Upgrade,
         "url": method.FC6_Method,
         "user": user.F8_User,
         "vnc": vnc.F9_Vnc,

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