pep8 cleanup

This commit is contained in:
Doug Hellmann 2012-06-01 10:37:13 -04:00
parent 9059e9538a
commit cb6222fec4
8 changed files with 40 additions and 22 deletions

View File

@ -28,14 +28,16 @@ class App(object):
:paramtype stdout: writable I/O stream
:param stderr: Standard error output stream
:paramtype stderr: writable I/O stream
:param interactive_app_factory: callable to create an interactive application
:param interactive_app_factory: callable to create an
interactive application
:paramtype interactive_app_factory: cliff.interactive.InteractiveApp
"""
NAME = os.path.splitext(os.path.basename(sys.argv[0]))[0]
CONSOLE_MESSAGE_FORMAT = '%(message)s'
LOG_FILE_MESSAGE_FORMAT = '[%(asctime)s] %(levelname)-8s %(name)s %(message)s'
LOG_FILE_MESSAGE_FORMAT = \
'[%(asctime)s] %(levelname)-8s %(name)s %(message)s'
DEFAULT_VERBOSE_LEVEL = 1
def __init__(self, description, version, command_manager,
@ -187,18 +189,26 @@ class App(object):
return
def interact(self):
interpreter = self.interactive_app_factory(self, self.command_manager, self.stdin, self.stdout)
interpreter = self.interactive_app_factory(self,
self.command_manager,
self.stdin,
self.stdout,
)
interpreter.cmdloop()
return 0
def run_subcommand(self, argv):
cmd_factory, cmd_name, sub_argv = self.command_manager.find_command(argv)
subcommand = self.command_manager.find_command(argv)
cmd_factory, cmd_name, sub_argv = subcommand
cmd = cmd_factory(self, self.options)
err = None
result = 1
try:
self.prepare_to_run_command(cmd)
full_name = cmd_name if self.interactive_mode else ' '.join([self.NAME, cmd_name])
full_name = (cmd_name
if self.interactive_mode
else ' '.join([self.NAME, cmd_name])
)
cmd_parser = cmd.get_parser(full_name)
parsed_args = cmd_parser.parse_args(sub_argv)
result = cmd.run(parsed_args)

View File

@ -55,7 +55,7 @@ class DisplayCommandBase(Command):
action='store',
choices=formatter_choices,
default=formatter_default,
help='the output format to use, defaults to %s' % formatter_default,
help='the output format, defaults to %s' % formatter_default,
)
formatter_group.add_argument(
'-c', '--column',

View File

@ -26,7 +26,9 @@ class CSVLister(ListFormatter):
)
def emit_list(self, column_names, data, stdout, parsed_args):
writer = csv.writer(stdout, quoting=self.QUOTE_MODES[parsed_args.quote_mode])
writer = csv.writer(stdout,
quoting=self.QUOTE_MODES[parsed_args.quote_mode],
)
writer.writerow(column_names)
for row in data:
writer.writerow(row)

View File

@ -9,7 +9,7 @@ class ShellFormatter(SingleFormatter):
def add_argument_group(self, parser):
group = parser.add_argument_group(
title='shell formatter',
description='Print values in a format a UNIX shell can parse (variable="value")',
description='a format a UNIX shell can parse (variable="value")',
)
group.add_argument(
'--variable',

View File

@ -39,7 +39,10 @@ class HelpCommand(Command):
def run(self, parsed_args):
if parsed_args.cmd:
try:
cmd_factory, cmd_name, search_args = self.app.command_manager.find_command(parsed_args.cmd)
the_cmd = self.app.command_manager.find_command(
parsed_args.cmd,
)
cmd_factory, cmd_name, search_args = the_cmd
except ValueError:
# Did not find an exact match
cmd = parsed_args.cmd[0]

View File

@ -22,7 +22,8 @@ class InteractiveApp(cmd2.Cmd):
:param parent_app: The calling application (expected to be derived
from :class:`cliff.main.App`).
:param command_manager: A :class:`cliff.commandmanager.CommandManager` instance.
:param command_manager: A :class:`cliff.commandmanager.CommandManager`
instance.
:param stdin: Standard input stream
:param stdout: Standard output stream
"""
@ -67,10 +68,11 @@ class InteractiveApp(cmd2.Cmd):
# coming from the command manager
arg_parts = shlex.split(arg)
method_name = '_'.join(
itertools.chain(['do'],
itertools.takewhile(lambda x: not x.startswith('-'),
arg_parts)
)
itertools.chain(
['do'],
itertools.takewhile(lambda x: not x.startswith('-'),
arg_parts)
)
)
# Have the command manager version of the help
# command produce the help text since cmd and
@ -102,7 +104,8 @@ class InteractiveApp(cmd2.Cmd):
# command names by default.
line_parts = shlex.split(statement.parsed.raw)
try:
cmd_factory, cmd_name, sub_argv = self.command_manager.find_command(line_parts)
the_cmd = self.command_manager.find_command(line_parts)
cmd_factory, cmd_name, sub_argv = the_cmd
except ValueError:
# Not a plugin command
pass

View File

@ -22,11 +22,10 @@ except IOError:
long_description = ''
install_requires = ['distribute',
# disabled until OpenStack catches up 'PrettyTable>=0.6',
'PrettyTable',
'cmd2',
'tablib',
]
'PrettyTable',
'cmd2',
'tablib',
]
try:
import argparse
except ImportError:
@ -48,7 +47,8 @@ def find_package_data(
exclude=standard_exclude,
exclude_directories=standard_exclude_directories,
only_in_packages=True,
show_ignored=False):
show_ignored=False,
):
"""
Return a dictionary suitable for use in ``package_data``
in a distutils ``setup.py`` file.

View File

@ -10,4 +10,4 @@ deps =
[testenv:pep8]
deps = pep8
commands = pep8 --repeat --ignore=E501 --show-source cliff setup.py
commands = pep8 --repeat --ignore=E501 --ignore=E123 --show-source cliff