[node-patches] Change in ovirt-node[master]: RFC: Use optparse when in argparse isn't available

mburns at redhat.com mburns at redhat.com
Sat May 18 22:37:08 UTC 2013


Michael Burns has uploaded a new change for review.

Change subject: RFC:  Use optparse when in argparse isn't available
......................................................................

RFC:  Use optparse when in argparse isn't available

Python 2.6 has optparse, but no argparse.  This patch attempts
to try argparse first, but fall back to optparse if it isn't
available.

NOTE:  this patch has not been tested at all.  A separate
logging issue with python 2.6 is blocking all testing.

Change-Id: Id9fdc1062f0dfbb1f7c8807981acdbf3fd805792
Signed-off-by: Mike Burns <mburns at redhat.com>
---
M src/ovirt/node/app.py
1 file changed, 23 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/57/14857/1

diff --git a/src/ovirt/node/app.py b/src/ovirt/node/app.py
index cf8f73e..8d0fd44 100644
--- a/src/ovirt/node/app.py
+++ b/src/ovirt/node/app.py
@@ -22,7 +22,6 @@
 from ovirt.node.config import defaults
 from ovirt.node.ui import urwid_builder
 from ovirt.node.utils import system, Timer, console
-import argparse
 import logging
 import logging.config
 import sys
@@ -127,14 +126,29 @@
         self.plugin_base = plugin_base
 
     def __parse_cmdline(self):
-        parser = argparse.ArgumentParser(description='oVirt Node Utility')
-        parser.add_argument("--defaults",
-                            type=str,
-                            help="Central oVirt Node configuration file")
-        parser.add_argument("--dry",
-                            action='store_true',
-                            help="Just write defaults, nothing else")
-        self.args = parser.parse_args()
+        try:
+            import argparse
+            parser = argparse.ArgumentParser(description='oVirt Node Utility')
+            parser.add_argument("--defaults",
+                                type=str,
+                                help="Central oVirt Node configuration file")
+            parser.add_argument("--dry",
+                                action='store_true',
+                                help="Just write defaults, nothing else")
+            self.args = parser.parse_args()
+        except:
+            from optparse import OptionParser
+            parser = OptionsParser()
+            parser.add_option("--defaults",
+                                dest="defaults",
+                                help="Central oVirt Node configuration file")
+            parser.add_option("--dry",
+                                action='store_true',
+                                dest="dry",
+                                default=False,
+                                help="Just write defaults, nothing else")
+            (options, self.args) = parser.parse_args()
+
         self.logger.debug("Parsed args: %s" % self.args)
         if self.args.defaults:
             # FIXME Should be read by clients


--
To view, visit http://gerrit.ovirt.org/14857
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9fdc1062f0dfbb1f7c8807981acdbf3fd805792
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Michael Burns <mburns at redhat.com>



More information about the node-patches mailing list