Moved test projects
This commit is contained in:
8
example/custom/api/src/appsettings.development.json
Normal file
8
example/custom/api/src/appsettings.development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
}
|
||||
}
|
||||
26
example/custom/api/src/appsettings.edrafts-pc.json
Normal file
26
example/custom/api/src/appsettings.edrafts-pc.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"TimeFormat": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
|
||||
"Log": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
},
|
||||
|
||||
"Database": {
|
||||
"Host": "localhost",
|
||||
"User": "cpl",
|
||||
"Port": 3306,
|
||||
"Password": "cpl",
|
||||
"Database": "cpl",
|
||||
"Charset": "utf8mb4",
|
||||
"UseUnicode": "true",
|
||||
"Buffered": "true"
|
||||
}
|
||||
}
|
||||
15
example/custom/api/src/appsettings.json
Normal file
15
example/custom/api/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"
|
||||
},
|
||||
|
||||
"Log": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "ERROR",
|
||||
"Level": "WARNING"
|
||||
}
|
||||
}
|
||||
47
example/custom/api/src/main.py
Normal file
47
example/custom/api/src/main.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
from cpl import api
|
||||
from cpl.api.application.web_app import WebApp
|
||||
from cpl.application import ApplicationBuilder
|
||||
from cpl.auth.permission.permissions import Permissions
|
||||
from cpl.auth.schema import AuthUser, Role
|
||||
from cpl.core.configuration import Configuration
|
||||
from cpl.core.environment import Environment
|
||||
from cpl.core.utils.cache import Cache
|
||||
from service import PingService
|
||||
|
||||
|
||||
def main():
|
||||
builder = ApplicationBuilder[WebApp](WebApp)
|
||||
|
||||
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)
|
||||
|
||||
# builder.services.add_logging()
|
||||
builder.services.add_structured_logging()
|
||||
builder.services.add_transient(PingService)
|
||||
builder.services.add_module(api)
|
||||
|
||||
builder.services.add_cache(AuthUser)
|
||||
builder.services.add_cache(Role)
|
||||
|
||||
app = builder.build()
|
||||
app.with_logging()
|
||||
app.with_database()
|
||||
|
||||
app.with_authentication()
|
||||
app.with_authorization()
|
||||
|
||||
app.with_route(path="/route1", fn=lambda r: JSONResponse("route1"), method="GET", authentication=True, permissions=[Permissions.administrator])
|
||||
app.with_routes_directory("routes")
|
||||
|
||||
provider = builder.service_provider
|
||||
user_cache = provider.get_service(Cache[AuthUser])
|
||||
role_cache = provider.get_service(Cache[Role])
|
||||
|
||||
app.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
0
example/custom/api/src/routes/__init__.py
Normal file
0
example/custom/api/src/routes/__init__.py
Normal file
16
example/custom/api/src/routes/ping.py
Normal file
16
example/custom/api/src/routes/ping.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from urllib.request import Request
|
||||
|
||||
from service import PingService
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
from cpl.api import APILogger
|
||||
from cpl.api.router import Router
|
||||
|
||||
|
||||
@Router.authenticate()
|
||||
# @Router.authorize(permissions=[Permissions.administrator])
|
||||
# @Router.authorize(policies=["test"])
|
||||
@Router.get(f"/ping")
|
||||
async def ping(r: Request, ping: PingService, logger: APILogger):
|
||||
logger.info(f"Ping: {ping}")
|
||||
return JSONResponse(ping.ping(r))
|
||||
4
example/custom/api/src/service.py
Normal file
4
example/custom/api/src/service.py
Normal file
@@ -0,0 +1,4 @@
|
||||
class PingService:
|
||||
|
||||
def ping(self, r):
|
||||
return "pong"
|
||||
41
example/custom/console/main.py
Normal file
41
example/custom/console/main.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import time
|
||||
from cpl.core.console import Console, ForegroundColorEnum
|
||||
|
||||
|
||||
def test_spinner():
|
||||
Console.write_line("test1")
|
||||
Console.write_line("test2", 2)
|
||||
Console.write_line("test3", 2, 3)
|
||||
Console.write_line("test4", 2, 3, 4)
|
||||
time.sleep(2)
|
||||
Console.write_line("test5")
|
||||
|
||||
|
||||
def test_console():
|
||||
Console.write_line("Hello World")
|
||||
Console.write("\nName: ")
|
||||
Console.write_line(" Hello", Console.read_line())
|
||||
Console.write_at(5, 5, "at 5, 5")
|
||||
Console.write_at(10, 10, "at 10, 10")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Console.write_line("Hello World\n")
|
||||
Console.clear()
|
||||
Console.spinner(
|
||||
"Test:", test_spinner, spinner_foreground_color=ForegroundColorEnum.cyan, text_foreground_color="green"
|
||||
)
|
||||
test_console()
|
||||
Console.write_line("HOLD BACK")
|
||||
opts = ["Option 1", "Option 2", "Option 3", "Option 4"]
|
||||
selected = Console.select(
|
||||
">",
|
||||
"Select item:",
|
||||
opts,
|
||||
header_foreground_color=ForegroundColorEnum.blue,
|
||||
option_foreground_color=ForegroundColorEnum.green,
|
||||
cursor_foreground_color=ForegroundColorEnum.red,
|
||||
)
|
||||
Console.write_line(f"You selected: {selected}")
|
||||
|
||||
Console.write_line()
|
||||
0
example/custom/database/LICENSE
Normal file
0
example/custom/database/LICENSE
Normal file
0
example/custom/database/README.md
Normal file
0
example/custom/database/README.md
Normal file
40
example/custom/database/cpl.json
Normal file
40
example/custom/database/cpl.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"Project": {
|
||||
"Name": "database",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
"Description": "",
|
||||
"LongDescription": "",
|
||||
"URL": "",
|
||||
"CopyrightDate": "",
|
||||
"CopyrightName": "",
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"sh_cpl==2021.4.2.dev1"
|
||||
],
|
||||
"PythonVersion": ">=3.9.2",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
},
|
||||
"Build": {
|
||||
"ProjectType": "console",
|
||||
"SourcePath": "src",
|
||||
"OutputPath": "dist",
|
||||
"Main": "main",
|
||||
"EntryPoint": "database",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {}
|
||||
}
|
||||
}
|
||||
39
example/custom/database/src/application.py
Normal file
39
example/custom/database/src/application.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from cpl.application.abc import ApplicationABC
|
||||
from cpl.auth.keycloak import KeycloakAdmin
|
||||
from cpl.core.console import Console
|
||||
from cpl.core.environment import Environment
|
||||
from cpl.core.log import LoggerABC
|
||||
from cpl.dependency import ServiceProviderABC
|
||||
from model.city import City
|
||||
from model.city_dao import CityDao
|
||||
from model.user import User
|
||||
from model.user_dao import UserDao
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
def __init__(self, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, services)
|
||||
|
||||
self._logger = services.get_service(LoggerABC)
|
||||
|
||||
async def test_daos(self):
|
||||
userDao: UserDao = self._services.get_service(UserDao)
|
||||
cityDao: CityDao = self._services.get_service(CityDao)
|
||||
|
||||
Console.write_line(await userDao.get_all())
|
||||
|
||||
if len(await cityDao.get_all()) == 0:
|
||||
city_id = await cityDao.create(City(0, "Haren", "49733"))
|
||||
await userDao.create(User(0, "NewUser", city_id))
|
||||
|
||||
Console.write_line(await userDao.get_all())
|
||||
|
||||
async def main(self):
|
||||
self._logger.debug(f"Host: {Environment.get_host_name()}")
|
||||
self._logger.debug(f"Environment: {Environment.get_environment()}")
|
||||
|
||||
await self.test_daos()
|
||||
|
||||
kc_admin: KeycloakAdmin = self._services.get_service(KeycloakAdmin)
|
||||
x = kc_admin.get_users()
|
||||
Console.write_line(x)
|
||||
8
example/custom/database/src/appsettings.development.json
Normal file
8
example/custom/database/src/appsettings.development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
}
|
||||
}
|
||||
22
example/custom/database/src/appsettings.edrafts-lapi.json
Normal file
22
example/custom/database/src/appsettings.edrafts-lapi.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"TimeFormat": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
|
||||
"Log": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
},
|
||||
|
||||
"Database": {
|
||||
"AuthPlugin": "mysql_native_password",
|
||||
"ConnectionString": "mysql+mysqlconnector://cpl:$credentials@localhost/cpl",
|
||||
"Credentials": "Y3Bs",
|
||||
"Encoding": "utf8mb4"
|
||||
}
|
||||
}
|
||||
26
example/custom/database/src/appsettings.edrafts-pc.json
Normal file
26
example/custom/database/src/appsettings.edrafts-pc.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"TimeFormat": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
|
||||
"Log": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "TRACE",
|
||||
"Level": "TRACE"
|
||||
},
|
||||
|
||||
"Database": {
|
||||
"Host": "localhost",
|
||||
"User": "cpl",
|
||||
"Port": 3306,
|
||||
"Password": "cpl",
|
||||
"Database": "cpl",
|
||||
"Charset": "utf8mb4",
|
||||
"UseUnicode": "true",
|
||||
"Buffered": "true"
|
||||
}
|
||||
}
|
||||
15
example/custom/database/src/appsettings.json
Normal file
15
example/custom/database/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"
|
||||
},
|
||||
|
||||
"Log": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLevel": "ERROR",
|
||||
"Level": "WARNING"
|
||||
}
|
||||
}
|
||||
5
example/custom/database/src/custom_permissions.py
Normal file
5
example/custom/database/src/custom_permissions.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class CustomPermissions(Enum):
|
||||
test = "test"
|
||||
19
example/custom/database/src/main.py
Normal file
19
example/custom/database/src/main.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from application import Application
|
||||
from cpl.application import ApplicationBuilder
|
||||
from custom_permissions import CustomPermissions
|
||||
from startup import Startup
|
||||
|
||||
|
||||
def main():
|
||||
builder = ApplicationBuilder(Application).with_startup(Startup)
|
||||
app = builder.build()
|
||||
|
||||
app.with_logging()
|
||||
app.with_permissions(CustomPermissions)
|
||||
app.with_migrations("./scripts")
|
||||
app.with_seeders()
|
||||
app.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
27
example/custom/database/src/main_simplified.py
Normal file
27
example/custom/database/src/main_simplified.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from application import Application
|
||||
from cpl.application import ApplicationBuilder
|
||||
from cpl.auth.permission.permissions_registry import PermissionsRegistry
|
||||
from cpl.core.console import Console
|
||||
from cpl.core.log import LogLevel
|
||||
from custom_permissions import CustomPermissions
|
||||
from startup import Startup
|
||||
|
||||
|
||||
def main():
|
||||
builder = ApplicationBuilder(Application).with_startup(Startup)
|
||||
builder.services.add_logging()
|
||||
|
||||
app = builder.build()
|
||||
|
||||
app.with_logging(LogLevel.trace)
|
||||
app.with_permissions(CustomPermissions)
|
||||
app.with_migrations("./scripts")
|
||||
app.with_seeders()
|
||||
|
||||
Console.write_line(CustomPermissions.test.value in PermissionsRegistry.get())
|
||||
app.run()
|
||||
Console.write_line("Hello from main_simplified.py!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
0
example/custom/database/src/model/__init__.py
Normal file
0
example/custom/database/src/model/__init__.py
Normal file
29
example/custom/database/src/model/city.py
Normal file
29
example/custom/database/src/model/city.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl.core.typing import SerialId
|
||||
from cpl.database.abc.db_model_abc import DbModelABC
|
||||
|
||||
|
||||
class City(DbModelABC):
|
||||
def __init__(
|
||||
self,
|
||||
id: int,
|
||||
name: str,
|
||||
zip: str,
|
||||
deleted: bool = False,
|
||||
editor_id: Optional[SerialId] = None,
|
||||
created: Optional[datetime] = None,
|
||||
updated: Optional[datetime] = None,
|
||||
):
|
||||
DbModelABC.__init__(self, id, deleted, editor_id, created, updated)
|
||||
self._name = name
|
||||
self._zip = zip
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def zip(self) -> str:
|
||||
return self._zip
|
||||
11
example/custom/database/src/model/city_dao.py
Normal file
11
example/custom/database/src/model/city_dao.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from cpl.database.abc import DbModelDaoABC
|
||||
from model.city import City
|
||||
|
||||
|
||||
class CityDao(DbModelDaoABC[City]):
|
||||
|
||||
def __init__(self):
|
||||
DbModelDaoABC.__init__(self, City, "city")
|
||||
|
||||
self.attribute(City.name, str)
|
||||
self.attribute(City.zip, int)
|
||||
30
example/custom/database/src/model/user.py
Normal file
30
example/custom/database/src/model/user.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl.core.typing import SerialId
|
||||
from cpl.database.abc.db_model_abc import DbModelABC
|
||||
|
||||
|
||||
class User(DbModelABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: int,
|
||||
name: str,
|
||||
city_id: int = 0,
|
||||
deleted: bool = False,
|
||||
editor_id: Optional[SerialId] = None,
|
||||
created: Optional[datetime] = None,
|
||||
updated: Optional[datetime] = None,
|
||||
):
|
||||
DbModelABC.__init__(self, id, deleted, editor_id, created, updated)
|
||||
self._name = name
|
||||
self._city_id = city_id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def city_id(self) -> int:
|
||||
return self._city_id
|
||||
13
example/custom/database/src/model/user_dao.py
Normal file
13
example/custom/database/src/model/user_dao.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from cpl.database.abc import DbModelDaoABC
|
||||
from model.user import User
|
||||
|
||||
|
||||
class UserDao(DbModelDaoABC[User]):
|
||||
|
||||
def __init__(self):
|
||||
DbModelDaoABC.__init__(self, User, "users")
|
||||
|
||||
self.attribute(User.name, str)
|
||||
self.attribute(User.city_id, int, db_name="CityId")
|
||||
|
||||
self.reference("city", "id", User.city_id, "city")
|
||||
22
example/custom/database/src/scripts/0-initial.sql
Normal file
22
example/custom/database/src/scripts/0-initial.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
CREATE TABLE IF NOT EXISTS `city` (
|
||||
`id` INT(30) NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(64) NOT NULL,
|
||||
`zip` VARCHAR(5) NOT NULL,
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
editorId INT NULL,
|
||||
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` INT(30) NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(64) NOT NULL,
|
||||
`cityId` INT(30),
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
editorId INT NULL,
|
||||
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`cityId`) REFERENCES city(`id`),
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
31
example/custom/database/src/startup.py
Normal file
31
example/custom/database/src/startup.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from cpl import auth
|
||||
from cpl.application.abc.startup_abc import StartupABC
|
||||
from cpl.auth import permission
|
||||
from cpl.core.configuration import Configuration
|
||||
from cpl.core.environment import Environment
|
||||
from cpl.core.log import Logger, LoggerABC
|
||||
from cpl.database import mysql
|
||||
from cpl.database.abc.data_access_object_abc import DataAccessObjectABC
|
||||
from cpl.dependency import ServiceCollection
|
||||
from model.city_dao import CityDao
|
||||
from model.user_dao import UserDao
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
@staticmethod
|
||||
async 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
|
||||
async def configure_services(services: ServiceCollection):
|
||||
services.add_module(mysql)
|
||||
services.add_module(auth)
|
||||
services.add_module(permission)
|
||||
|
||||
services.add_transient(DataAccessObjectABC, UserDao)
|
||||
services.add_transient(DataAccessObjectABC, CityDao)
|
||||
|
||||
services.add_singleton(LoggerABC, Logger)
|
||||
0
example/custom/database/src/tests/__init__.py
Normal file
0
example/custom/database/src/tests/__init__.py
Normal file
0
example/custom/di/LICENSE
Normal file
0
example/custom/di/LICENSE
Normal file
0
example/custom/di/README.md
Normal file
0
example/custom/di/README.md
Normal file
15
example/custom/di/appsettings.json
Normal file
15
example/custom/di/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"
|
||||
}
|
||||
}
|
||||
9
example/custom/di/cpl-workspace.json
Normal file
9
example/custom/di/cpl-workspace.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Workspace": {
|
||||
"DefaultProject": "di",
|
||||
"Projects": {
|
||||
"di": "src/di/di.json"
|
||||
},
|
||||
"Scripts": {}
|
||||
}
|
||||
}
|
||||
0
example/custom/di/src/di/__init__.py
Normal file
0
example/custom/di/src/di/__init__.py
Normal file
42
example/custom/di/src/di/application.py
Normal file
42
example/custom/di/src/di/application.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from cpl.application.abc import ApplicationABC
|
||||
from cpl.core.console.console import Console
|
||||
from cpl.dependency import ServiceProviderABC
|
||||
from cpl.dependency.scope import Scope
|
||||
from di.static_test import StaticTest
|
||||
from di.test_abc import TestABC
|
||||
from di.test_service import TestService
|
||||
from di.di_tester_service import DITesterService
|
||||
from di.tester import Tester
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
def __init__(self, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, services)
|
||||
|
||||
def _part_of_scoped(self):
|
||||
ts: TestService = self._services.get_service(TestService)
|
||||
ts.run()
|
||||
|
||||
def configure(self): ...
|
||||
|
||||
def main(self):
|
||||
with self._services.create_scope() as scope:
|
||||
Console.write_line("Scope1")
|
||||
ts: TestService = scope.service_provider.get_service(TestService)
|
||||
ts.run()
|
||||
dit: DITesterService = scope.service_provider.get_service(DITesterService)
|
||||
dit.run()
|
||||
|
||||
with self._services.create_scope() as scope:
|
||||
Console.write_line("Scope2")
|
||||
ts: TestService = scope.service_provider.get_service(TestService)
|
||||
ts.run()
|
||||
dit: DITesterService = scope.service_provider.get_service(DITesterService)
|
||||
dit.run()
|
||||
|
||||
Console.write_line("Global")
|
||||
self._part_of_scoped()
|
||||
StaticTest.test()
|
||||
|
||||
self._services.get_service(Tester)
|
||||
Console.write_line(self._services.get_services(list[TestABC]))
|
||||
44
example/custom/di/src/di/di.json
Normal file
44
example/custom/di/src/di/di.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"Project": {
|
||||
"Name": "di",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
"Description": "",
|
||||
"LongDescription": "",
|
||||
"URL": "",
|
||||
"CopyrightDate": "",
|
||||
"CopyrightName": "",
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core==2022.12.0"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2022.12.0"
|
||||
],
|
||||
"PythonVersion": ">=3.9.2",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
},
|
||||
"Build": {
|
||||
"ProjectType": "console",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "di.main",
|
||||
"EntryPoint": "di",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
||||
11
example/custom/di/src/di/di_tester_service.py
Normal file
11
example/custom/di/src/di/di_tester_service.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from cpl.core.console.console import Console
|
||||
from di.test_service import TestService
|
||||
|
||||
|
||||
class DITesterService:
|
||||
def __init__(self, ts: TestService):
|
||||
self._ts = ts
|
||||
|
||||
def run(self):
|
||||
Console.write_line("DIT: ")
|
||||
self._ts.run()
|
||||
14
example/custom/di/src/di/main.py
Normal file
14
example/custom/di/src/di/main.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from cpl.application import ApplicationBuilder
|
||||
|
||||
from di.application import Application
|
||||
from di.startup import Startup
|
||||
|
||||
|
||||
def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.with_startup(Startup)
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
25
example/custom/di/src/di/startup.py
Normal file
25
example/custom/di/src/di/startup.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from cpl.application.abc import StartupABC
|
||||
from cpl.dependency import ServiceProviderABC, ServiceCollection
|
||||
from di.di_tester_service import DITesterService
|
||||
from di.test1_service import Test1Service
|
||||
from di.test2_service import Test2Service
|
||||
from di.test_abc import TestABC
|
||||
from di.test_service import TestService
|
||||
from di.tester import Tester
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self): ...
|
||||
|
||||
def configure_services(self, services: ServiceCollection) -> ServiceProviderABC:
|
||||
services.add_scoped(TestService)
|
||||
services.add_scoped(DITesterService)
|
||||
|
||||
services.add_singleton(TestABC, Test1Service)
|
||||
services.add_singleton(TestABC, Test2Service)
|
||||
services.add_singleton(Tester)
|
||||
|
||||
return services.build()
|
||||
9
example/custom/di/src/di/static_test.py
Normal file
9
example/custom/di/src/di/static_test.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from cpl.dependency import ServiceProvider, ServiceProviderABC
|
||||
from di.test_service import TestService
|
||||
|
||||
|
||||
class StaticTest:
|
||||
@staticmethod
|
||||
@ServiceProvider.inject
|
||||
def test(services: ServiceProviderABC, t1: TestService):
|
||||
t1.run()
|
||||
12
example/custom/di/src/di/test1_service.py
Normal file
12
example/custom/di/src/di/test1_service.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import string
|
||||
from cpl.core.console.console import Console
|
||||
from cpl.core.utils.string import String
|
||||
from di.test_abc import TestABC
|
||||
|
||||
|
||||
class Test1Service(TestABC):
|
||||
def __init__(self):
|
||||
TestABC.__init__(self, String.random_string(string.ascii_lowercase, 8))
|
||||
|
||||
def run(self):
|
||||
Console.write_line(f"Im {self._name}")
|
||||
12
example/custom/di/src/di/test2_service.py
Normal file
12
example/custom/di/src/di/test2_service.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import string
|
||||
from cpl.core.console.console import Console
|
||||
from cpl.core.utils.string import String
|
||||
from di.test_abc import TestABC
|
||||
|
||||
|
||||
class Test2Service(TestABC):
|
||||
def __init__(self):
|
||||
TestABC.__init__(self, String.random_string(string.ascii_lowercase, 8))
|
||||
|
||||
def run(self):
|
||||
Console.write_line(f"Im {self._name}")
|
||||
9
example/custom/di/src/di/test_abc.py
Normal file
9
example/custom/di/src/di/test_abc.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from abc import ABC
|
||||
|
||||
|
||||
class TestABC(ABC):
|
||||
def __init__(self, name: str):
|
||||
self._name = name
|
||||
|
||||
def __repr__(self):
|
||||
return f"<{type(self).__name__} {self._name}>"
|
||||
12
example/custom/di/src/di/test_service.py
Normal file
12
example/custom/di/src/di/test_service.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import string
|
||||
|
||||
from cpl.core.console.console import Console
|
||||
from cpl.core.utils.string import String
|
||||
|
||||
|
||||
class TestService:
|
||||
def __init__(self):
|
||||
self._name = String.random(8)
|
||||
|
||||
def run(self):
|
||||
Console.write_line(f"Im {self._name}")
|
||||
8
example/custom/di/src/di/tester.py
Normal file
8
example/custom/di/src/di/tester.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from cpl.core.console.console import Console
|
||||
from di.test_abc import TestABC
|
||||
|
||||
|
||||
class Tester:
|
||||
def __init__(self, t1: TestABC, t2: TestABC, t3: list[TestABC]):
|
||||
Console.write_line("Tester:")
|
||||
Console.write_line(t1, t2, t3)
|
||||
0
example/custom/di/src/tests/__init__.py
Normal file
0
example/custom/di/src/tests/__init__.py
Normal file
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")
|
||||
0
example/custom/translation/LICENSE
Normal file
0
example/custom/translation/LICENSE
Normal file
0
example/custom/translation/README.md
Normal file
0
example/custom/translation/README.md
Normal file
9
example/custom/translation/cpl-workspace.json
Normal file
9
example/custom/translation/cpl-workspace.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Workspace": {
|
||||
"DefaultProject": "translation",
|
||||
"Projects": {
|
||||
"translation": "src/translation/translation.json"
|
||||
},
|
||||
"Scripts": {}
|
||||
}
|
||||
}
|
||||
0
example/custom/translation/src/tests/__init__.py
Normal file
0
example/custom/translation/src/tests/__init__.py
Normal file
27
example/custom/translation/src/translation/application.py
Normal file
27
example/custom/translation/src/translation/application.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from cpl.application import ApplicationABC
|
||||
from cpl.core.configuration import ConfigurationABC
|
||||
from cpl.core.console import Console
|
||||
from cpl.dependency import ServiceProviderABC
|
||||
from cpl.translation.translate_pipe import TranslatePipe
|
||||
from cpl.translation.translation_service_abc import TranslationServiceABC
|
||||
from cpl.translation.translation_settings import TranslationSettings
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
self._translate: TranslatePipe = services.get_service(TranslatePipe)
|
||||
self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC)
|
||||
self._translation_settings: TranslationSettings = config.get_configuration(TranslationSettings)
|
||||
|
||||
self._translation.load_by_settings(config.get_configuration(TranslationSettings))
|
||||
self._translation.set_default_lang("de")
|
||||
|
||||
def configure(self): ...
|
||||
|
||||
def main(self):
|
||||
Console.write_line(self._translate.transform("main.text.hello_world"))
|
||||
self._translation.set_lang("en")
|
||||
Console.write_line(self._translate.transform("main.text.hello_world"))
|
||||
Console.write_line(self._translate.transform("main.text.hello"))
|
||||
23
example/custom/translation/src/translation/appsettings.json
Normal file
23
example/custom/translation/src/translation/appsettings.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"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"
|
||||
},
|
||||
|
||||
"Translation": {
|
||||
"Languages":[
|
||||
"de",
|
||||
"en"
|
||||
],
|
||||
"DefaultLanguage": "en"
|
||||
}
|
||||
}
|
||||
14
example/custom/translation/src/translation/main.py
Normal file
14
example/custom/translation/src/translation/main.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from cpl.application import ApplicationBuilder
|
||||
|
||||
from translation.application import Application
|
||||
from translation.startup import Startup
|
||||
|
||||
|
||||
def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.with_startup(Startup)
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
17
example/custom/translation/src/translation/startup.py
Normal file
17
example/custom/translation/src/translation/startup.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from cpl.application import StartupABC
|
||||
from cpl.core.configuration import ConfigurationABC
|
||||
from cpl.dependency import ServiceProviderABC, ServiceCollection
|
||||
from cpl.core.environment import Environment
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: Environment) -> ConfigurationABC:
|
||||
configuration.add_json_file("appsettings.json")
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollection, environment: Environment) -> ServiceProviderABC:
|
||||
services.add_translation()
|
||||
return services.build()
|
||||
44
example/custom/translation/src/translation/translation.json
Normal file
44
example/custom/translation/src/translation/translation.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"Project": {
|
||||
"Name": "translation",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
"Description": "",
|
||||
"LongDescription": "",
|
||||
"URL": "",
|
||||
"CopyrightDate": "",
|
||||
"CopyrightName": "",
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.0"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli>=2022.6.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
},
|
||||
"Build": {
|
||||
"ProjectType": "console",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "translation.main",
|
||||
"EntryPoint": "translation",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"main": {
|
||||
"text": {
|
||||
"hello_world": "Hallo Welt"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"main": {
|
||||
"text": {
|
||||
"hello_world": "Hello World"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user