Add support for python >= 3.4

Python 3.4 changed some of the output from argparse and the
handling of default func and command behaviour; this patch
deals with both < and >= 3.4 behaviour.

Change-Id: I27983f7b06fc16aeedb98a4b36f7ff9a451706ec
Closes-Bug: 1496805
This commit is contained in:
James Page 2015-09-17 11:34:59 +01:00
parent 58d7c91024
commit 5eb6725bde
3 changed files with 10 additions and 6 deletions

View File

@ -420,7 +420,8 @@ class OpenStackMagnumShell(object):
args = subcommand_parser.parse_args(argv)
# Short-circuit and deal with help right away.
if args.func == self.do_help:
# NOTE(jamespage): args.func is not guaranteed with python >= 3.4
if not hasattr(args, 'func') or args.func == self.do_help:
self.do_help(args)
return 0
elif args.func == self.do_bash_completion:
@ -551,7 +552,10 @@ class OpenStackMagnumShell(object):
help='Display help for <subcommand>.')
def do_help(self, args):
"""Display help about this program or one of its subcommands."""
if args.command:
# NOTE(jamespage): args.command is not guaranteed with python >= 3.4
command = getattr(args, 'command', '')
if command:
if args.command in self.subcommands:
self.subcommands[args.command].print_help()
else:

View File

@ -36,13 +36,13 @@ class TestCommandLineArgument(utils.TestCase):
_mandatory_arg_error = [
'.*?^usage: ',
'.*?^error: argument',
'.*?^error: (the following arguments|argument)',
".*?^Try 'magnum help ",
]
_few_argument_error = [
'.*?^usage: magnum ',
'.*?^error: too few arguments',
'.*?^error: (the following arguments|too few arguments)',
".*?^Try"
]
@ -189,7 +189,7 @@ class TestCommandLineArgument(utils.TestCase):
def test_bay_update_failure_few_args(self, mock_update):
_error_msg = [
'.*?^usage: magnum bay-update ',
'.*?^error: too few arguments',
'.*?^error: (the following arguments|too few arguments)',
".*?^Try 'magnum help bay-update' for more information."
]
self._test_arg_failure('bay-update', _error_msg)

View File

@ -1,6 +1,6 @@
[tox]
minversion = 1.6
envlist = py26,py27,py33,pypy,pep8
envlist = py26,py27,py33,py34,pypy,pep8
skipsdist = True
[testenv]