Modularization
Some checks failed
Test before pr merge / test-lint (pull_request) Failing after 7s
Build on push / prepare (push) Successful in 10s
Build on push / core (push) Successful in 18s
Build on push / query (push) Successful in 17s
Build on push / dependency (push) Successful in 17s
Build on push / application (push) Successful in 16s
Build on push / mail (push) Successful in 15s
Build on push / database (push) Successful in 15s
Build on push / translation (push) Successful in 18s
Build on push / auth (push) Successful in 23s
Build on push / api (push) Successful in 16s
Some checks failed
Test before pr merge / test-lint (pull_request) Failing after 7s
Build on push / prepare (push) Successful in 10s
Build on push / core (push) Successful in 18s
Build on push / query (push) Successful in 17s
Build on push / dependency (push) Successful in 17s
Build on push / application (push) Successful in 16s
Build on push / mail (push) Successful in 15s
Build on push / database (push) Successful in 15s
Build on push / translation (push) Successful in 18s
Build on push / auth (push) Successful in 23s
Build on push / api (push) Successful in 16s
This commit is contained in:
0
example/general/src/__init__.py
Normal file
0
example/general/src/__init__.py
Normal file
81
example/general/src/application.py
Normal file
81
example/general/src/application.py
Normal file
@@ -0,0 +1,81 @@
|
||||
import time
|
||||
|
||||
from cpl.application.abc import ApplicationABC
|
||||
from cpl.core.configuration import Configuration
|
||||
from cpl.core.console import Console
|
||||
from cpl.core.environment import Environment
|
||||
from cpl.core.log import LoggerABC
|
||||
from cpl.core.pipes import IPAddressPipe
|
||||
from cpl.dependency import ServiceProvider
|
||||
from cpl.mail import EMail, EMailClientABC
|
||||
from cpl.query import List
|
||||
from scoped_service import ScopedService
|
||||
from test_service import TestService
|
||||
from test_settings import TestSettings
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, services: ServiceProvider):
|
||||
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(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))
|
||||
|
||||
root_scoped_service = self._services.get_service(ScopedService)
|
||||
with self._services.create_scope() as scope:
|
||||
s_srvc1 = scope.get_service(ScopedService)
|
||||
s_srvc2 = scope.get_service(ScopedService)
|
||||
|
||||
Console.write_line(root_scoped_service)
|
||||
Console.write_line(s_srvc1)
|
||||
Console.write_line(s_srvc2)
|
||||
if root_scoped_service == s_srvc1 or s_srvc1 != s_srvc2:
|
||||
raise Exception("Root scoped service should not be equal to scoped service")
|
||||
|
||||
root_scoped_service2 = self._services.get_service(ScopedService)
|
||||
Console.write_line(root_scoped_service2)
|
||||
if root_scoped_service == root_scoped_service2:
|
||||
raise Exception("Root scoped service should be equal to root scoped service 2")
|
||||
|
||||
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()
|
||||
|
||||
x = 0
|
||||
while x < 5:
|
||||
Console.write_line("Running...")
|
||||
x += 1
|
||||
time.sleep(5)
|
||||
8
example/general/src/appsettings.development.json
Normal file
8
example/general/src/appsettings.development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
}
|
||||
}
|
||||
20
example/general/src/appsettings.edrafts-lapi.json
Normal file
20
example/general/src/appsettings.edrafts-lapi.json
Normal file
@@ -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=="
|
||||
}
|
||||
}
|
||||
37
example/general/src/appsettings.edrafts-pc.json
Normal file
37
example/general/src/appsettings.edrafts-pc.json
Normal file
@@ -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/general/src/appsettings.json
Normal file
15
example/general/src/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/general/src/db/__init__.py
Normal file
1
example/general/src/db/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
20
example/general/src/hosted_service.py
Normal file
20
example/general/src/hosted_service.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from cpl.core.console import Console
|
||||
from cpl.dependency.hosted.hosted_service import HostedService
|
||||
|
||||
|
||||
class Hosted(HostedService):
|
||||
def __init__(self):
|
||||
self._stopped = False
|
||||
|
||||
async def start(self):
|
||||
Console.write_line("Hosted Service Started")
|
||||
while not self._stopped:
|
||||
Console.write_line("Hosted Service Running")
|
||||
await asyncio.sleep(5)
|
||||
|
||||
async def stop(self):
|
||||
Console.write_line("Hosted Service Stopped")
|
||||
self._stopped = True
|
||||
17
example/general/src/main.py
Normal file
17
example/general/src/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()
|
||||
10
example/general/src/scoped_service.py
Normal file
10
example/general/src/scoped_service.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from cpl.core.console import Console
|
||||
|
||||
|
||||
class ScopedService:
|
||||
def __init__(self):
|
||||
self.value = "I am a scoped service"
|
||||
Console.write_line(self.value, self)
|
||||
|
||||
def get_value(self):
|
||||
return self.value
|
||||
28
example/general/src/startup.py
Normal file
28
example/general/src/startup.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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 cpl.mail.mail_module import MailModule
|
||||
from hosted_service import Hosted
|
||||
from scoped_service import ScopedService
|
||||
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(MailModule)
|
||||
services.add_transient(IPAddressPipe)
|
||||
services.add_singleton(TestService)
|
||||
services.add_scoped(ScopedService)
|
||||
services.add_hosted_service(Hosted)
|
||||
10
example/general/src/test_extension.py
Normal file
10
example/general/src/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 ServiceProvider
|
||||
|
||||
|
||||
class TestExtension(ApplicationExtensionABC):
|
||||
|
||||
@staticmethod
|
||||
def run(services: ServiceProvider):
|
||||
Console.write_line("Hello World from App Extension")
|
||||
13
example/general/src/test_service.py
Normal file
13
example/general/src/test_service.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from cpl.core.console.console import Console
|
||||
from cpl.dependency import ServiceProvider
|
||||
from cpl.core.pipes.ip_address_pipe import IPAddressPipe
|
||||
|
||||
|
||||
class TestService:
|
||||
def __init__(self, provider: ServiceProvider):
|
||||
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/general/src/test_settings.py
Normal file
6
example/general/src/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/general/src/test_startup_extension.py
Normal file
14
example/general/src/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")
|
||||
Reference in New Issue
Block a user