Moved test projects
This commit is contained in:
20
example/custom/general/.cpl/schematic_custom.py
Normal file
20
example/custom/general/.cpl/schematic_custom.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Custom(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
class $Name:
|
||||
|
||||
def __init__(self):
|
||||
print('hello')
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "custom", ["cm", "CM"])
|
||||
8
example/custom/general/cpl-workspace.json
Normal file
8
example/custom/general/cpl-workspace.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Workspace": {
|
||||
"DefaultProject": "general",
|
||||
"Projects": {
|
||||
"general": "src/general/general.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
0
example/custom/general/src/general/__init__.py
Normal file
0
example/custom/general/src/general/__init__.py
Normal file
64
example/custom/general/src/general/application.py
Normal file
64
example/custom/general/src/general/application.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from cpl.application.abc import ApplicationABC
|
||||
from cpl.core.configuration import Configuration
|
||||
from cpl.core.console import Console
|
||||
from cpl.dependency import ServiceProviderABC
|
||||
from cpl.core.environment import Environment
|
||||
from cpl.core.log import LoggerABC
|
||||
from cpl.core.pipes import IPAddressPipe
|
||||
from cpl.mail import EMail, EMailClientABC
|
||||
from cpl.query.extension.list import List
|
||||
from test_service import TestService
|
||||
from test_settings import TestSettings
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, services)
|
||||
self._logger = self._services.get_service(LoggerABC)
|
||||
self._mailer = self._services.get_service(EMailClientABC)
|
||||
|
||||
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 - {Environment.get_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 main(self):
|
||||
self._logger.debug(f"Host: {Environment.get_host_name()}")
|
||||
self._logger.debug(f"Environment: {Environment.get_environment()}")
|
||||
Console.write_line(List(int, range(0, 10)).select(lambda x: f"x={x}").to_list())
|
||||
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)
|
||||
|
||||
test_settings = Configuration.get(TestSettings)
|
||||
Console.write_line(test_settings.value)
|
||||
Console.write_line("reload config")
|
||||
Configuration.add_json_file(f"appsettings.json")
|
||||
Configuration.add_json_file(f"appsettings.{Environment.get_environment()}.json")
|
||||
Configuration.add_json_file(f"appsettings.{Environment.get_host_name()}.json", optional=True)
|
||||
test_settings1 = Configuration.get(TestSettings)
|
||||
Console.write_line(test_settings1.value)
|
||||
# self.test_send_mail()
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"TimeFormat": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
"Logging": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
},
|
||||
"EMailClient": {
|
||||
"Host": "mail.sh-edraft.de",
|
||||
"Port": "587",
|
||||
"UserName": "dev-srv@sh-edraft.de",
|
||||
"Credentials": "RmBOQX1eNFYiYjgsSid3fV1nelc2WA=="
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"TimeFormat": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
|
||||
"Logging": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
},
|
||||
|
||||
"EMailClient": {
|
||||
"Host": "mail.sh-edraft.de",
|
||||
"Port": "587",
|
||||
"UserName": "dev-srv@sh-edraft.de",
|
||||
"Credentials": "RmBOQX1eNFYiYjgsSid3fV1nelc2WA=="
|
||||
},
|
||||
|
||||
"Database": {
|
||||
"Host": "localhost",
|
||||
"User": "sh_cpl",
|
||||
"Password": "MHZhc0Y2bjhKc1VUMWV0Qw==",
|
||||
"Database": "sh_cpl",
|
||||
"Charset": "utf8mb4",
|
||||
"UseUnicode": "true",
|
||||
"Buffered": "true",
|
||||
"AuthPlugin": "mysql_native_password"
|
||||
},
|
||||
|
||||
"Test": {
|
||||
"Value": 20
|
||||
}
|
||||
}
|
||||
15
example/custom/general/src/general/appsettings.json
Normal file
15
example/custom/general/src/general/appsettings.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"TimeFormat": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
|
||||
"Logging": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "ERROR",
|
||||
"Level": "WARN"
|
||||
}
|
||||
}
|
||||
1
example/custom/general/src/general/db/__init__.py
Normal file
1
example/custom/general/src/general/db/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
51
example/custom/general/src/general/general.json
Normal file
51
example/custom/general/src/general/general.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"Project": {
|
||||
"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.10.0.post9",
|
||||
"cpl-translation==2022.10.0.post2",
|
||||
"cpl-query==2022.10.0.post2"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2022.10"
|
||||
],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {
|
||||
"linux": "../../venv/bin/python",
|
||||
"win32": ""
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"Build": {
|
||||
"ProjectType": "console",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "dist",
|
||||
"Main": "main",
|
||||
"EntryPoint": "",
|
||||
"IncludePackageData": true,
|
||||
"Included": [
|
||||
"*/templates"
|
||||
],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
||||
17
example/custom/general/src/general/main.py
Normal file
17
example/custom/general/src/general/main.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from application import Application
|
||||
from cpl.application import ApplicationBuilder
|
||||
from test_extension import TestExtension
|
||||
from startup import Startup
|
||||
from test_startup_extension import TestStartupExtension
|
||||
|
||||
|
||||
def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.with_startup(Startup)
|
||||
app_builder.with_extension(TestStartupExtension)
|
||||
app_builder.with_extension(TestExtension)
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
23
example/custom/general/src/general/startup.py
Normal file
23
example/custom/general/src/general/startup.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from cpl import mail
|
||||
from cpl.application.abc import StartupABC
|
||||
from cpl.core.configuration import Configuration
|
||||
from cpl.core.environment import Environment
|
||||
from cpl.core.pipes import IPAddressPipe
|
||||
from cpl.dependency import ServiceCollection
|
||||
from test_service import TestService
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
@staticmethod
|
||||
def configure_configuration():
|
||||
Configuration.add_json_file(f"appsettings.json")
|
||||
Configuration.add_json_file(f"appsettings.{Environment.get_environment()}.json")
|
||||
Configuration.add_json_file(f"appsettings.{Environment.get_host_name()}.json", optional=True)
|
||||
|
||||
@staticmethod
|
||||
def configure_services(services: ServiceCollection):
|
||||
services.add_logging()
|
||||
services.add_module(mail)
|
||||
services.add_transient(IPAddressPipe)
|
||||
services.add_singleton(TestService)
|
||||
10
example/custom/general/src/general/test_extension.py
Normal file
10
example/custom/general/src/general/test_extension.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from cpl.application.abc import ApplicationExtensionABC
|
||||
from cpl.core.console import Console
|
||||
from cpl.dependency import ServiceProviderABC
|
||||
|
||||
|
||||
class TestExtension(ApplicationExtensionABC):
|
||||
|
||||
@staticmethod
|
||||
def run(services: ServiceProviderABC):
|
||||
Console.write_line("Hello World from App Extension")
|
||||
13
example/custom/general/src/general/test_service.py
Normal file
13
example/custom/general/src/general/test_service.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from cpl.core.console.console import Console
|
||||
from cpl.dependency import ServiceProviderABC
|
||||
from cpl.core.pipes.ip_address_pipe import IPAddressPipe
|
||||
|
||||
|
||||
class TestService:
|
||||
def __init__(self, provider: ServiceProviderABC):
|
||||
self._provider = provider
|
||||
|
||||
def run(self):
|
||||
Console.write_line("Hello World!", self._provider)
|
||||
ip = [192, 168, 178, 30]
|
||||
Console.write_line(ip, IPAddressPipe.to_str(ip))
|
||||
6
example/custom/general/src/general/test_settings.py
Normal file
6
example/custom/general/src/general/test_settings.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from cpl.core.configuration import ConfigurationModelABC
|
||||
|
||||
|
||||
class TestSettings(ConfigurationModelABC):
|
||||
def __init__(self, value: int = None):
|
||||
self.value = value
|
||||
14
example/custom/general/src/general/test_startup_extension.py
Normal file
14
example/custom/general/src/general/test_startup_extension.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from cpl.application.abc import StartupExtensionABC
|
||||
from cpl.core.console import Console
|
||||
from cpl.dependency import ServiceCollection
|
||||
|
||||
|
||||
class TestStartupExtension(StartupExtensionABC):
|
||||
|
||||
@staticmethod
|
||||
def configure_configuration():
|
||||
Console.write_line("config")
|
||||
|
||||
@staticmethod
|
||||
def configure_services(services: ServiceCollection):
|
||||
Console.write_line("services")
|
||||
0
example/custom/general/test/__init__.py
Normal file
0
example/custom/general/test/__init__.py
Normal file
3
example/custom/general/test/custom.py
Normal file
3
example/custom/general/test/custom.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class Custom:
|
||||
def __init__(self):
|
||||
print("hello")
|
||||
Reference in New Issue
Block a user