1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#!/usr/bin/python3
#-----------------------------------------------------------------------------
# Copyright (c) 2013, The BiPy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
__credits__ = ["Daniel McDonald", "Greg Caporaso", "Doug Wendel",
"Jai Ram Rideout"]
from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)
from pyqi.commands.code_header_generator import CodeHeaderGenerator
command_imports = """from pyqi.core.command import (Command, CommandIn, CommandOut,
ParameterCollection)"""
command_format = """class %s(Command):
BriefDescription = "FILL IN A 1 SENTENCE DESCRIPTION"
LongDescription = "GO INTO MORE DETAIL"
CommandIns = ParameterCollection([
CommandIn(Name='foo', DataType=str,
Description='some required parameter', Required=True),
CommandIn(Name='bar', DataType=int,
Description='some optional parameter', Required=False,
Default=1)
])
CommandOuts = ParameterCollection([
CommandOut(Name="result_1", DataType=str, Description="xyz"),
CommandOut(Name="result_2", DataType=str, Description="123"),
])
def run(self, **kwargs):
# EXAMPLE:
# return {'result_1': kwargs['foo'] * kwargs['bar'],
# 'result_2': "Some output bits"}
raise NotImplementedError("You must define this method")
CommandConstructor = %s"""
test_format = """from unittest import TestCase, main
from FILL IN MODULE PATH import %(name)s
class %(name)sTests(TestCase):
def setUp(self):
self.cmd_obj = %(name)s()
def test_run(self):
self.fail()
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")
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)
]
)
CommandOuts = ParameterCollection([
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']
result_lines = code_header_lines
if kwargs['test_code']:
result_lines.extend(
(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'))
return {'result': result_lines}
CommandConstructor = MakeCommand
|