cpl@2022.6.3 - Verbesserung der Parameter #67

Merged
edraft merged 25 commits from 2022.6.3 into 2022.6 2022-05-22 17:38:22 +02:00
4 changed files with 62 additions and 11 deletions
Showing only changes of commit 7b823e1141 - Show all commits

View File

@ -0,0 +1,41 @@
import textwrap
from string import Template
from cpl_core.utils.string import String
from cpl_cli._templates.template_file_abc import TemplateFileABC
class ValidatorTemplate(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("""\
from cpl_core.configuration.validator_abc import ValidatorABC
class $Name(ValidatorABC):
def __init__(self):
ValidatorABC.__init__(self)
def validate(self) -> bool:
return True
""")
@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
)

View File

@ -2,6 +2,7 @@ import os
import sys import sys
import textwrap import textwrap
from cpl_cli._templates.generate.validator_template import ValidatorTemplate
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.console.foreground_color_enum import ForegroundColorEnum from cpl_core.console.foreground_color_enum import ForegroundColorEnum
from cpl_core.console.console import Console from cpl_core.console.console import Console
@ -50,6 +51,10 @@ class GenerateService(CommandABC):
"thread": { "thread": {
"Upper": "Thread", "Upper": "Thread",
"Template": ThreadTemplate "Template": ThreadTemplate
},
"validator": {
"Upper": "Validator",
"Template": ValidatorTemplate
} }
} }
@ -73,6 +78,7 @@ class GenerateService(CommandABC):
service service
settings settings
thread thread
validator
""") """)
@staticmethod @staticmethod
@ -89,7 +95,9 @@ class GenerateService(CommandABC):
'class (c|C)', 'class (c|C)',
'enum (e|E)', 'enum (e|E)',
'service (s|S)', 'service (s|S)',
'settings (st|ST)' 'settings (st|ST)',
'thread (t|T)',
'validator (v|V)'
] ]
Console.write_line('Available Schematics:') Console.write_line('Available Schematics:')
for name in schematics: for name in schematics:

View File

@ -68,7 +68,8 @@ class StartupArgumentExtension(StartupExtensionABC):
.add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 't'], ' ') .add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'validator', ['v', 'V'], ' ')
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallService, True) \ config.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallService, True) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \ .add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) .add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])

View File

@ -287,16 +287,17 @@ class Configuration(ConfigurationABC):
if prevent: if prevent:
continue continue
abort = False if exe.validators is not None:
for validator_type in exe.validators: abort = False
validator: ValidatorABC = services.get_service(validator_type) for validator_type in exe.validators:
result = validator.validate() validator: ValidatorABC = services.get_service(validator_type)
abort = not result result = validator.validate()
if abort: abort = not result
break if abort:
break
if abort: if abort:
continue continue
cmd: CommandABC = services.get_service(exe.executable_type) cmd: CommandABC = services.get_service(exe.executable_type)
self.add_configuration('ACTIVE_EXECUTABLE', exe.name) self.add_configuration('ACTIVE_EXECUTABLE', exe.name)