Added all schematics to command generate

This commit is contained in:
2021-03-12 15:32:37 +01:00
parent 2ad97d5021
commit c9b612d552
7 changed files with 239 additions and 30 deletions

View File

@@ -1,12 +1,19 @@
import textwrap
from string import Template
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class ABCTemplate:
@staticmethod
def get_abc_py(name: str) -> str:
string = textwrap.dedent("""\
class ABCTemplate(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 abc import ABC, abstractmethod
@@ -14,9 +21,18 @@ class ABCTemplate:
@abstractmethod
def __init__(self): pass
""")
return Template(string).substitute(
Name=name
@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

@@ -0,0 +1,35 @@
import textwrap
from string import Template
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class ClassTemplate(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("""\
class $Name:
def __init__(self):
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
)

View File

@@ -0,0 +1,54 @@
import textwrap
from string import Template
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class ConfigModelTemplate(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 traceback
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console import Console
class $Name(ConfigurationModelABC):
def __init__(self):
ConfigurationModelABC.__init__(self)
self._atr = ''
@property
def atr(self) -> str:
return self._atr
def from_dict(self, settings: dict):
try:
self._atr = settings['atr']
except Exception as e:
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
""")
@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

@@ -0,0 +1,37 @@
import textwrap
from string import Template
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class EnumTemplate(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 enum import Enum
class $Name(Enum):
atr = 0
""")
@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

@@ -0,0 +1,38 @@
import textwrap
from string import Template
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class ServiceTemplate(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.dependency_injection import ServiceABC
class $Name(ServiceABC):
def __init__(self):
ServiceABC.__init__(self)
""")
@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
)