Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.
Open

Pep8 #259

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pyqi/commands/code_header_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

__credits__ = ["Jai Ram Rideout", "Daniel McDonald"]

from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)
from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)


class CodeHeaderGenerator(Command):
BriefDescription = "Generate header code for use in a Python file"
Expand Down
31 changes: 17 additions & 14 deletions pyqi/commands/make_bash_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@
from __future__ import division

__credits__ = ["Daniel McDonald", "Jai Ram Rideout", "Doug Wendel",
"Greg Caporaso"]
"Greg Caporaso"]

import importlib
from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)
from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)
from pyqi.core.interface import get_command_names, get_command_config


def _get_cfg_module(desc):
"""Load a module"""
mod = importlib.import_module(desc)
return mod

# Based on http://stackoverflow.com/questions/5302650/multi-level-bash-completion
# Based on
# http://stackoverflow.com/questions/5302650/multi-level-bash-completion
script_fmt = """_%(driver)s_complete()
{
local cur prev
Expand All @@ -34,7 +36,7 @@ def _get_cfg_module(desc):

if [ $COMP_CWORD -gt 1 ]; then
prev=${COMP_WORDS[1]}
fi
fi

if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -W "%(command_list)s" -- $cur) )
Expand All @@ -56,11 +58,12 @@ def _get_cfg_module(desc):
;;
"""


class BashCompletion(Command):
BriefDescription = "Construct a bash completion script"
LongDescription = ("Construct a bash tab completion script that will search"
" through available commands and options")
LongDescription = ("Construct a bash tab completion script that will "
"search through available commands and options")

CommandIns = ParameterCollection([
CommandIn(Name='command_config_module', DataType=str,
Description="CLI command configuration module",
Expand All @@ -77,7 +80,6 @@ class BashCompletion(Command):
def run(self, **kwargs):
driver = kwargs['driver_name']
cfg_mod_path = kwargs['command_config_module']
cfg_mod = _get_cfg_module(cfg_mod_path)
command_names = get_command_names(cfg_mod_path)
command_list = ' '.join(command_names)

Expand All @@ -89,14 +91,15 @@ def run(self, **kwargs):
if cmd_cfg is not None:
command_options = []
command_options.extend(
sorted(['--%s' % p.Name for p in cmd_cfg.inputs]))
sorted(['--%s' % p.Name for p in cmd_cfg.inputs]))
opts = ' '.join(command_options)

commands.append(command_fmt % {'command':cmd, 'options':opts})
commands.append(command_fmt %
{'command': cmd, 'options': opts})

all_commands = ''.join(commands)
return {'result':script_fmt % {'driver':driver,
'commands':all_commands,
'command_list':command_list}}
return {'result': script_fmt % {'driver': driver,
'commands': all_commands,
'command_list': command_list}}

CommandConstructor = BashCompletion
40 changes: 20 additions & 20 deletions pyqi/commands/make_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
__credits__ = ["Daniel McDonald", "Greg Caporaso", "Doug Wendel",
"Jai Ram Rideout"]

from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)
from pyqi.core.command import CommandIn, CommandOut, ParameterCollection
from pyqi.commands.code_header_generator import CodeHeaderGenerator

command_imports = """from pyqi.core.command import (Command, CommandIn, CommandOut,
command_imports = """from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)"""

command_format = """class %s(Command):
Expand Down Expand Up @@ -56,43 +55,44 @@ def test_run(self):
if __name__ == '__main__':
main()"""


class MakeCommand(CodeHeaderGenerator):
BriefDescription = "Construct a stubbed out Command object"
LongDescription = ("This command is intended to construct the basics of a "
"Command object so that a developer can dive straight into the "
"implementation of the command")
"Command object so that a developer can dive straight "
"into the implementation of the command")

CommandIns = ParameterCollection(
CodeHeaderGenerator.CommandIns.Parameters + [
CommandIn(Name='name', DataType=str,
Description='the name of the Command', Required=True),
CommandIn(Name='test_code', DataType=bool,
Description='create stubbed out unit test code',
Required=False, Default=False)
]
CodeHeaderGenerator.CommandIns.Parameters + [
CommandIn(Name='name', DataType=str,
Description='the name of the Command', Required=True),
CommandIn(Name='test_code', DataType=bool,
Description='create stubbed out unit test code',
Required=False, Default=False)
]
)
CommandOuts = ParameterCollection([
CommandOut(Name='result',DataType=list,
Description='The resulting template')
]
CommandOut(Name='result', DataType=list,
Description='The resulting template')
]
)

def run(self, **kwargs):
code_header_lines = super(MakeCommand, self).run(
author=kwargs['author'], email=kwargs['email'],
license=kwargs['license'], copyright=kwargs['copyright'],
version=kwargs['version'], credits=kwargs['credits'])['result']
author=kwargs['author'], email=kwargs['email'],
license=kwargs['license'], copyright=kwargs['copyright'],
version=kwargs['version'], credits=kwargs['credits'])['result']

result_lines = code_header_lines

if kwargs['test_code']:
result_lines.extend(
(test_format % {'name': kwargs['name']}).split('\n'))
(test_format % {'name': kwargs['name']}).split('\n'))
else:
result_lines.extend(command_imports.split('\n'))
result_lines.append('')
result_lines.extend((command_format % (
kwargs['name'], kwargs['name'])).split('\n'))
kwargs['name'], kwargs['name'])).split('\n'))

return {'result': result_lines}

Expand Down
44 changes: 23 additions & 21 deletions pyqi/commands/make_optparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

from __future__ import division
from operator import attrgetter
from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)
from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)
from pyqi.commands.code_header_generator import CodeHeaderGenerator

__credits__ = ["Daniel McDonald", "Jai Ram Rideout", "Greg Caporaso",
Expand Down Expand Up @@ -81,7 +81,7 @@
# # value will be made available to Handler. This name
# # can be either an underscored or dashed version of the
# # option name (e.g., 'output_fp' or 'output-fp')
# InputName='output-fp'),
# InputName='output-fp'),
#
# An example option that does not map to a CommandIn.
# OptparseResult(Parameter=cmd_out_lookup('some_other_result'),
Expand Down Expand Up @@ -109,16 +109,19 @@
default_block_format = """# Default=%(default)s, # implied by Parameter
# DefaultDescription=%(default_description)s, # implied by Parameter"""


class MakeOptparse(CodeHeaderGenerator):
BriefDescription = "Consume a Command, stub out an optparse configuration"
LongDescription = """Construct and stub out the basic optparse configuration for a given Command. This template provides comments and examples of what to fill in."""

LongDescription = "Construct and stub out the basic optparse "\
"configuration for a given Command. This template "\
"provides comments and examples of what to fill in."

CommandIns = ParameterCollection(
CodeHeaderGenerator.CommandIns.Parameters + [
CommandIn(Name='command', DataType=Command,
Description='an existing Command', Required=True),
CommandIn(Name='command_module', DataType=str,
Description='the Command source module', Required=True)
CommandIn(Name='command', DataType=Command,
Description='an existing Command', Required=True),
CommandIn(Name='command_module', DataType=str,
Description='the Command source module', Required=True)
]
)

Expand All @@ -129,9 +132,9 @@ class MakeOptparse(CodeHeaderGenerator):

def run(self, **kwargs):
code_header_lines = super(MakeOptparse, self).run(
author=kwargs['author'], email=kwargs['email'],
license=kwargs['license'], copyright=kwargs['copyright'],
version=kwargs['version'], credits=kwargs['credits'])['result']
author=kwargs['author'], email=kwargs['email'],
license=kwargs['license'], copyright=kwargs['copyright'],
version=kwargs['version'], credits=kwargs['credits'])['result']

result_lines = code_header_lines

Expand All @@ -143,8 +146,8 @@ def run(self, **kwargs):
default_block = ''
else:
default_fmt = {
'default': repr(cmdin.Default),
'default_description': repr(cmdin.DefaultDescription)
'default': repr(cmdin.Default),
'default_description': repr(cmdin.DefaultDescription)
}
default_block = default_block_format % default_fmt

Expand All @@ -155,23 +158,22 @@ def run(self, **kwargs):
action = 'store'
data_type = cmdin.DataType

fmt = {'name':cmdin.Name, 'datatype':data_type, 'action':action,
'required':str(cmdin.Required),
'help':cmdin.Description, 'default_block':default_block}
fmt = {'name': cmdin.Name, 'datatype': data_type, 'action': action,
'required': str(cmdin.Required),
'help': cmdin.Description, 'default_block': default_block}
cmdin_formatted.append(input_format % fmt)

cmdout_formatted = []
for cmdin in sorted(kwargs['command'].CommandOuts.values(),
key=attrgetter('Name')):
fmt = {'name':cmdin.Name}
fmt = {'name': cmdin.Name}
cmdout_formatted.append(output_format % fmt)


cmdin_formatted = ''.join(cmdin_formatted)
cmdout_formatted = ''.join(cmdout_formatted)
header_fmt = {'command_module':kwargs['command_module'],
header_fmt = {'command_module': kwargs['command_module'],
'input_fmt': cmdin_formatted,
'output_fmt':cmdout_formatted}
'output_fmt': cmdout_formatted}

result_lines.extend((header_format % header_fmt).split('\n'))
return {'result': result_lines}
Expand Down
Loading