Added thread schematic

This commit is contained in:
Sven Heidemann 2021-03-12 16:01:44 +01:00
parent ac63751583
commit b3b65f3dd2
3 changed files with 48 additions and 1 deletions

View File

@ -12,6 +12,7 @@ from cpl_cli.templates.generate.class_template import ClassTemplate
from cpl_cli.templates.generate.configmodel_template import ConfigModelTemplate from cpl_cli.templates.generate.configmodel_template import ConfigModelTemplate
from cpl_cli.templates.generate.enum_template import EnumTemplate from cpl_cli.templates.generate.enum_template import EnumTemplate
from cpl_cli.templates.generate.service_template import ServiceTemplate from cpl_cli.templates.generate.service_template import ServiceTemplate
from cpl_cli.templates.generate.thread_template import ThreadTemplate
from cpl_cli.templates.template_file_abc import TemplateFileABC from cpl_cli.templates.template_file_abc import TemplateFileABC
@ -40,6 +41,10 @@ class Generate(CommandABC):
"settings": { "settings": {
"Upper": "Settings", "Upper": "Settings",
"Template": ConfigModelTemplate "Template": ConfigModelTemplate
},
"thread": {
"Upper": "Thread",
"Template": ThreadTemplate
} }
} }

View File

@ -48,7 +48,8 @@ class Startup(StartupABC):
ConsoleArgument('', 'class', ['c', 'C'], ' '), ConsoleArgument('', 'class', ['c', 'C'], ' '),
ConsoleArgument('', 'enum', ['e', 'E'], ' '), ConsoleArgument('', 'enum', ['e', 'E'], ' '),
ConsoleArgument('', 'service', ['s', 'S'], ' '), ConsoleArgument('', 'service', ['s', 'S'], ' '),
ConsoleArgument('', 'settings', ['st', 'ST'], ' ') ConsoleArgument('', 'settings', ['st', 'ST'], ' '),
ConsoleArgument('', 'thread', ['t', 't'], ' ')
])) ]))
self._configuration.add_console_argument(ConsoleArgument('', 'help', ['h', 'H'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'help', ['h', 'H'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'new', ['n', 'N'], '', [ self._configuration.add_console_argument(ConsoleArgument('', 'new', ['n', 'N'], '', [

View File

@ -0,0 +1,41 @@
import textwrap
from string import Template
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class ThreadTemplate(TemplateFileABC):
def __init__(self, name: str, schematic: str, schematic_upper: str, path: str):
TemplateFileABC.__init__(self)
self._name = f'{String.convert_to_snake_case(name)}_{schematic}.py'
self._class_name = f'{String.first_to_upper(name)}{schematic_upper}'
self._path = path
self._value = textwrap.dedent("""\
import threading
class $Name(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self) -> None:
pass
""")
@property
def name(self) -> str:
return self._name
@property
def path(self) -> str:
return self._path
@property
def value(self) -> str:
return Template(self._value).substitute(
Name=self._class_name
)