Improved project file structure
This commit is contained in:
8
tests/custom/general/cpl-workspace.json
Normal file
8
tests/custom/general/cpl-workspace.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Workspace": {
|
||||
"DefaultProject": "general",
|
||||
"Projects": {
|
||||
"general": "src/general/general.json"
|
||||
}
|
||||
}
|
||||
}
|
61
tests/custom/general/src/general/application.py
Normal file
61
tests/custom/general/src/general/application.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.application.application_abc import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_core.mailing import EMailClientABC, EMail
|
||||
from cpl_core.pipes import IPAddressPipe
|
||||
from test_service import TestService
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
self._logger: Optional[LoggerABC] = None
|
||||
self._mailer: Optional[EMailClientABC] = None
|
||||
|
||||
def test_send_mail(self):
|
||||
mail = EMail()
|
||||
mail.add_header('Mime-Version: 1.0')
|
||||
mail.add_header('Content-Type: text/plain; charset=utf-8')
|
||||
mail.add_header('Content-Transfer-Encoding: quoted-printable')
|
||||
mail.add_receiver('sven.heidemann@sh-edraft.de')
|
||||
mail.subject = f'Test - {self._configuration.environment.host_name}'
|
||||
mail.body = 'Dies ist ein Test :D'
|
||||
self._mailer.send_mail(mail)
|
||||
|
||||
@staticmethod
|
||||
def _wait(time_ms: int):
|
||||
time.sleep(time_ms)
|
||||
|
||||
def configure(self):
|
||||
self._logger = self._services.get_service(LoggerABC)
|
||||
self._mailer = self._services.get_service(EMailClientABC)
|
||||
|
||||
def main(self):
|
||||
self._configuration.parse_console_arguments(self._services)
|
||||
|
||||
if self._configuration.environment.application_name != '':
|
||||
self._logger.header(f'{self._configuration.environment.application_name}:')
|
||||
self._logger.debug(__name__, f'Args: {self._configuration.additional_arguments}')
|
||||
self._logger.debug(__name__, f'Host: {self._configuration.environment.host_name}')
|
||||
self._logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}')
|
||||
self._logger.debug(__name__, f'Customer: {self._configuration.environment.customer}')
|
||||
Console.spinner('Test', self._wait, 2, spinner_foreground_color='red')
|
||||
test: TestService = self._services.get_service(TestService)
|
||||
ip_pipe: IPAddressPipe = self._services.get_service(IPAddressPipe)
|
||||
test.run()
|
||||
test2: TestService = self._services.get_service(TestService)
|
||||
ip_pipe2: IPAddressPipe = self._services.get_service(IPAddressPipe)
|
||||
Console.write_line(f'DI working: {test == test2 and ip_pipe != ip_pipe2}')
|
||||
Console.write_line(self._services.get_service(LoggerABC))
|
||||
|
||||
scope = self._services.create_scope()
|
||||
Console.write_line('scope', scope)
|
||||
with self._services.create_scope() as s:
|
||||
Console.write_line('with scope', s)
|
||||
# self.test_send_mail()
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "TRACE",
|
||||
"FileLogLevel": "TRACE"
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"TimeFormatSettings": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "TRACE",
|
||||
"FileLogLevel": "TRACE"
|
||||
},
|
||||
"EMailClientSettings": {
|
||||
"Host": "mail.sh-edraft.de",
|
||||
"Port": "587",
|
||||
"UserName": "dev-srv@sh-edraft.de",
|
||||
"Credentials": "RmBOQX1eNFYiYjgsSid3fV1nelc2WA=="
|
||||
},
|
||||
"PublishSettings": {
|
||||
"SourcePath": "../",
|
||||
"DistPath": "../../dist",
|
||||
"Templates": [
|
||||
{
|
||||
"TemplatePath": "../../publish_templates/all_template.txt",
|
||||
"Name": "all",
|
||||
"Description": "",
|
||||
"LongDescription": "",
|
||||
"CopyrightDate": "2020",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": ", see LICENSE for more details.",
|
||||
"Title": "",
|
||||
"Author": "Sven Heidemann",
|
||||
"Version": {
|
||||
"Major": 2020,
|
||||
"Minor": 12,
|
||||
"Micro": 9
|
||||
}
|
||||
},
|
||||
{
|
||||
"TemplatePath": "../../publish_templates/all_template.txt",
|
||||
"Name": "sh_edraft",
|
||||
"Description": "common python library",
|
||||
"LongDescription": "Library to share common classes and models used at sh-edraft.de",
|
||||
"CopyrightDate": "2020",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": ", see LICENSE for more details.",
|
||||
"Title": "",
|
||||
"Author": "Sven Heidemann",
|
||||
"Version": {
|
||||
"Major": 2020,
|
||||
"Minor": 12,
|
||||
"Micro": 9
|
||||
}
|
||||
}
|
||||
],
|
||||
"IncludedFiles": [],
|
||||
"ExcludedFiles": [],
|
||||
"TemplateEnding": "_template.txt"
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"TimeFormatSettings": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "TRACE",
|
||||
"FileLogLevel": "TRACE"
|
||||
},
|
||||
|
||||
"EMailClientSettings": {
|
||||
"Host": "mail.sh-edraft.de",
|
||||
"Port": "587",
|
||||
"UserName": "dev-srv@sh-edraft.de",
|
||||
"Credentials": "RmBOQX1eNFYiYjgsSid3fV1nelc2WA=="
|
||||
},
|
||||
|
||||
"DatabaseSettings": {
|
||||
"Host": "localhost",
|
||||
"User": "sh_cpl",
|
||||
"Password": "MHZhc0Y2bjhKc1VUMWV0Qw==",
|
||||
"Database": "sh_cpl",
|
||||
"Charset": "utf8mb4",
|
||||
"UseUnicode": "true",
|
||||
"Buffered": "true",
|
||||
"AuthPlugin": "mysql_native_password"
|
||||
}
|
||||
}
|
15
tests/custom/general/src/general/appsettings.json
Normal file
15
tests/custom/general/src/general/appsettings.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"TimeFormatSettings": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "ERROR",
|
||||
"FileLogLevel": "WARN"
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
from cpl_core.configuration import ConfigurationABC, ArgumentExecutableABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class GenerateArgument(ArgumentExecutableABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
ArgumentExecutableABC.__init__(self)
|
||||
self._config = config
|
||||
self._env = env
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
Console.error('Generate:')
|
||||
Console.write_line(args, self._env.environment_name)
|
@@ -0,0 +1,11 @@
|
||||
from cpl_core.configuration import ArgumentExecutableABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class InstallArgument(ArgumentExecutableABC):
|
||||
|
||||
def __init__(self):
|
||||
ArgumentExecutableABC.__init__(self)
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
Console.write_line('Install:', args)
|
25
tests/custom/general/src/general/db/__init__.py
Normal file
25
tests/custom/general/src/general/db/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'tests.db'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2021, minor=4, micro=1)
|
47
tests/custom/general/src/general/general.json
Normal file
47
tests/custom/general/src/general/general.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "general",
|
||||
"Version": {
|
||||
"Major": "2021",
|
||||
"Minor": "04",
|
||||
"Micro": "01"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "sh-edraft Common Python library",
|
||||
"LongDescription": "sh-edraft Common Python library",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2020 - 2021",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl_core==2022.6.1"
|
||||
],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {
|
||||
"linux": "../../venv/bin/python",
|
||||
"win32": ""
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "console",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "dist",
|
||||
"Main": "main",
|
||||
"EntryPoint": "",
|
||||
"IncludePackageData": true,
|
||||
"Included": [
|
||||
"*/templates"
|
||||
],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
19
tests/custom/general/src/general/main.py
Normal file
19
tests/custom/general/src/general/main.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from application import Application
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
from test_extension import TestExtension
|
||||
from startup import Startup
|
||||
from test_startup_extension import TestStartupExtension
|
||||
from parameter_startup import ParameterStartup
|
||||
|
||||
|
||||
def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.use_startup(Startup)
|
||||
app_builder.use_extension(ParameterStartup)
|
||||
app_builder.use_extension(TestStartupExtension)
|
||||
app_builder.use_extension(TestExtension)
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
31
tests/custom/general/src/general/parameter_startup.py
Normal file
31
tests/custom/general/src/general/parameter_startup.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from arguments.generate_argument import GenerateArgument
|
||||
from arguments.install_argument import InstallArgument
|
||||
from cpl_core.application import StartupExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC, ArgumentTypeEnum
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class ParameterStartup(StartupExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupExtensionABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'generate', ['g', 'G'], GenerateArgument) \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '-', 'o', ['o', 'O'], '=') \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallArgument) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services \
|
||||
.add_transient(GenerateArgument) \
|
||||
.add_singleton(InstallArgument)
|
31
tests/custom/general/src/general/startup.py
Normal file
31
tests/custom/general/src/general/startup.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC, ServiceProviderABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_core.logging import Logger, LoggerABC
|
||||
from cpl_core.mailing import EMailClient, EMailClientABC
|
||||
from cpl_core.pipes import IPAddressPipe
|
||||
from test_service import TestService
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC) -> ConfigurationABC:
|
||||
config.add_environment_variables('PYTHON_')
|
||||
config.add_environment_variables('CPLT_')
|
||||
config.add_json_file(f'appsettings.json')
|
||||
config.add_json_file(f'appsettings.{config.environment.environment_name}.json')
|
||||
config.add_json_file(f'appsettings.{config.environment.host_name}.json', optional=True)
|
||||
|
||||
return config
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC) -> ServiceProviderABC:
|
||||
services.add_singleton(LoggerABC, Logger)
|
||||
services.add_singleton(EMailClientABC, EMailClient)
|
||||
services.add_transient(IPAddressPipe)
|
||||
services.add_singleton(TestService)
|
||||
|
||||
return services.build_service_provider()
|
13
tests/custom/general/src/general/test_extension.py
Normal file
13
tests/custom/general/src/general/test_extension.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from cpl_core.application import ApplicationExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class TestExtension(ApplicationExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationExtensionABC.__init__(self)
|
||||
|
||||
def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
Console.write_line('Hello World from App Extension')
|
16
tests/custom/general/src/general/test_service.py
Normal file
16
tests/custom/general/src/general/test_service.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.pipes.ip_address_pipe import IPAddressPipe
|
||||
|
||||
|
||||
class TestService:
|
||||
|
||||
def __init__(self, provider: ServiceProviderABC, ip_pipe: IPAddressPipe):
|
||||
|
||||
self._provider = provider
|
||||
self._ip_pipe = ip_pipe
|
||||
|
||||
def run(self):
|
||||
Console.write_line('Hello World!', self._provider)
|
||||
ip = [192, 168, 178, 30]
|
||||
Console.write_line(ip, self._ip_pipe.transform(ip))
|
17
tests/custom/general/src/general/test_startup_extension.py
Normal file
17
tests/custom/general/src/general/test_startup_extension.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from cpl_core.application import StartupExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class TestStartupExtension(StartupExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupExtensionABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
Console.write_line('config')
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
Console.write_line('services')
|
Reference in New Issue
Block a user