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:
parent
58d7c91024
commit
5eb6725bde
@ -420,7 +420,8 @@ class OpenStackMagnumShell(object):
|
|||||||
args = subcommand_parser.parse_args(argv)
|
args = subcommand_parser.parse_args(argv)
|
||||||
|
|
||||||
# Short-circuit and deal with help right away.
|
# 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)
|
self.do_help(args)
|
||||||
return 0
|
return 0
|
||||||
elif args.func == self.do_bash_completion:
|
elif args.func == self.do_bash_completion:
|
||||||
@ -551,7 +552,10 @@ class OpenStackMagnumShell(object):
|
|||||||
help='Display help for <subcommand>.')
|
help='Display help for <subcommand>.')
|
||||||
def do_help(self, args):
|
def do_help(self, args):
|
||||||
"""Display help about this program or one of its subcommands."""
|
"""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:
|
if args.command in self.subcommands:
|
||||||
self.subcommands[args.command].print_help()
|
self.subcommands[args.command].print_help()
|
||||||
else:
|
else:
|
||||||
|
@ -36,13 +36,13 @@ class TestCommandLineArgument(utils.TestCase):
|
|||||||
|
|
||||||
_mandatory_arg_error = [
|
_mandatory_arg_error = [
|
||||||
'.*?^usage: ',
|
'.*?^usage: ',
|
||||||
'.*?^error: argument',
|
'.*?^error: (the following arguments|argument)',
|
||||||
".*?^Try 'magnum help ",
|
".*?^Try 'magnum help ",
|
||||||
]
|
]
|
||||||
|
|
||||||
_few_argument_error = [
|
_few_argument_error = [
|
||||||
'.*?^usage: magnum ',
|
'.*?^usage: magnum ',
|
||||||
'.*?^error: too few arguments',
|
'.*?^error: (the following arguments|too few arguments)',
|
||||||
".*?^Try"
|
".*?^Try"
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ class TestCommandLineArgument(utils.TestCase):
|
|||||||
def test_bay_update_failure_few_args(self, mock_update):
|
def test_bay_update_failure_few_args(self, mock_update):
|
||||||
_error_msg = [
|
_error_msg = [
|
||||||
'.*?^usage: magnum bay-update ',
|
'.*?^usage: magnum bay-update ',
|
||||||
'.*?^error: too few arguments',
|
'.*?^error: (the following arguments|too few arguments)',
|
||||||
".*?^Try 'magnum help bay-update' for more information."
|
".*?^Try 'magnum help bay-update' for more information."
|
||||||
]
|
]
|
||||||
self._test_arg_failure('bay-update', _error_msg)
|
self._test_arg_failure('bay-update', _error_msg)
|
||||||
|
2
tox.ini
2
tox.ini
@ -1,6 +1,6 @@
|
|||||||
[tox]
|
[tox]
|
||||||
minversion = 1.6
|
minversion = 1.6
|
||||||
envlist = py26,py27,py33,pypy,pep8
|
envlist = py26,py27,py33,py34,pypy,pep8
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user