Improved cpl g templating & added custom templating #137

This commit is contained in:
2022-12-05 19:57:27 +01:00
parent d6e3b37f7f
commit d1c93abe2c
34 changed files with 527 additions and 539 deletions

View File

View File

@@ -0,0 +1,30 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class ABC(GenerateSchematicABC):
def __init__(self, *args):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
from abc import ABC, abstractmethod
class $Name(ABC):
@abstractmethod
def __init__(self): pass
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'abc',
['a', 'A']
)

View File

@@ -0,0 +1,28 @@
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
from cpl_core.utils import String
class Class(GenerateSchematicABC):
def __init__(self, name: str, path: str, schematic: str):
GenerateSchematicABC.__init__(self, name, path, schematic)
self._name = f'{String.convert_to_snake_case(name)}.py'
self._class_name = f'{String.first_to_upper(name)}'
def get_code(self) -> str:
code = """\
class $Name:
def __init__(self):
pass
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'class',
['c', 'C']
)

View File

@@ -0,0 +1,46 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class ConfigModel(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
import traceback
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.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 {type(self).__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'settings',
['st', 'ST']
)

View File

@@ -0,0 +1,29 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class Enum(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
from enum import Enum
class $Name(Enum):
atr = 0
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'enum',
['e', 'E']
)

View File

@@ -0,0 +1,25 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class Init(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
self._name = f'__init__.py'
def get_code(self) -> str:
code = """\
# imports
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'init',
[]
)

View File

@@ -0,0 +1,32 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class Pipe(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
from cpl_core.pipes.pipe_abc import PipeABC
class $Name(PipeABC):
def __init__(self): pass
def transform(self, value: any, *args):
return value
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'pipe',
['p', 'P']
)

View File

@@ -0,0 +1,27 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class Service(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
class $Name:
def __init__(self):
pass
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'service',
['s', 'S']
)

View File

@@ -0,0 +1,33 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class TestCase(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
import unittest
class $Name(unittest.TestCase):
def setUp(self):
pass
def test_equal(self):
pass
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'test-case',
['tc', 'TC']
)

View File

@@ -0,0 +1,33 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class Thread(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
import threading
class $Name(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self) -> None:
pass
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'thread',
['t', 'T']
)

View File

@@ -0,0 +1,33 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class Validator(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
from cpl_core.configuration.validator_abc import ValidatorABC
class $Name(ValidatorABC):
def __init__(self):
ValidatorABC.__init__(self)
def validate(self) -> bool:
return True
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'validator',
['v', 'V']
)