Updated docs
This commit is contained in:
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -5,7 +5,6 @@ from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
@@ -13,4 +12,4 @@ class Application(ApplicationABC):
|
||||
pass
|
||||
|
||||
async def main(self):
|
||||
Console.write_line('Hello World')
|
||||
Console.write_line("Hello World")
|
||||
|
@@ -12,6 +12,6 @@ async def main():
|
||||
await app.run_async()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
|
@@ -5,12 +5,15 @@ from cpl_core.environment import ApplicationEnvironment
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
async def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
async def configure_configuration(
|
||||
self, configuration: ConfigurationABC, environment: ApplicationEnvironment
|
||||
) -> ConfigurationABC:
|
||||
return configuration
|
||||
|
||||
async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
async def configure_services(
|
||||
self, services: ServiceCollectionABC, environment: ApplicationEnvironment
|
||||
) -> ServiceProviderABC:
|
||||
return services.build_service_provider()
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -3,26 +3,28 @@ 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)
|
||||
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')
|
||||
Console.write_line("test5")
|
||||
|
||||
|
||||
def test_console():
|
||||
Console.write_line('Hello World')
|
||||
Console.write('\nName: ')
|
||||
Console.write_line(' Hello', Console.read_line())
|
||||
Console.write_line("Hello World")
|
||||
Console.write("\nName: ")
|
||||
Console.write_line(" Hello", Console.read_line())
|
||||
Console.clear()
|
||||
Console.write_at(5, 5, 'at 5, 5')
|
||||
Console.write_at(10, 10, 'at 10, 10')
|
||||
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.spinner('Test:', test_spinner, spinner_foreground_color=ForegroundColorEnum.cyan, text_foreground_color='green')
|
||||
if __name__ == "__main__":
|
||||
Console.write_line("Hello World\n")
|
||||
Console.spinner(
|
||||
"Test:", test_spinner, spinner_foreground_color=ForegroundColorEnum.cyan, text_foreground_color="green"
|
||||
)
|
||||
# opts = [
|
||||
# 'Option 1',
|
||||
# 'Option 2',
|
||||
|
@@ -10,7 +10,6 @@ from model.user_repo import UserRepo
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
@@ -20,19 +19,19 @@ class Application(ApplicationABC):
|
||||
self._logger = self._services.get_service(LoggerABC)
|
||||
|
||||
def main(self):
|
||||
self._logger.header(f'{self._configuration.environment.application_name}:')
|
||||
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}')
|
||||
self._logger.header(f"{self._configuration.environment.application_name}:")
|
||||
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}")
|
||||
|
||||
user_repo: UserRepo = self._services.get_service(UserRepoABC)
|
||||
if len(user_repo.get_users()) == 0:
|
||||
user_repo.add_test_user()
|
||||
|
||||
Console.write_line('Users:')
|
||||
|
||||
Console.write_line("Users:")
|
||||
for user in user_repo.get_users():
|
||||
Console.write_line(user.UserId, user.Name, user.City)
|
||||
|
||||
Console.write_line('Cities:')
|
||||
Console.write_line("Cities:")
|
||||
for city in user_repo.get_cities():
|
||||
Console.write_line(city.CityId, city.Name, city.ZIP)
|
||||
|
@@ -10,5 +10,5 @@ def main():
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@@ -2,46 +2,53 @@ from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class CityModel(TableABC):
|
||||
|
||||
def __init__(self, name: str, zip_code: str, id = 0):
|
||||
def __init__(self, name: str, zip_code: str, id=0):
|
||||
self.CityId = id
|
||||
self.Name = name
|
||||
self.ZIP = zip_code
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_create_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `City` (
|
||||
`CityId` INT(30) NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(64) NOT NULL,
|
||||
`ZIP` VARCHAR(5) NOT NULL,
|
||||
PRIMARY KEY(`CityId`)
|
||||
);
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `City` (
|
||||
`Name`, `ZIP`
|
||||
) VALUES (
|
||||
'{self.Name}',
|
||||
'{self.ZIP}'
|
||||
);
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `City`
|
||||
SET `Name` = '{self.Name}',
|
||||
`ZIP` = '{self.ZIP}',
|
||||
WHERE `CityId` = {self.Id};
|
||||
""")
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `City`
|
||||
WHERE `CityId` = {self.Id};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -3,6 +3,5 @@ from cpl_core.database.context import DatabaseContext
|
||||
|
||||
|
||||
class DBContext(DatabaseContext):
|
||||
|
||||
def __init__(self, db_settings: DatabaseSettings):
|
||||
DatabaseContext.__init__(self, db_settings)
|
||||
|
@@ -4,8 +4,7 @@ from .city_model import CityModel
|
||||
|
||||
|
||||
class UserModel(TableABC):
|
||||
|
||||
def __init__(self, name: str, city: CityModel, id = 0):
|
||||
def __init__(self, name: str, city: CityModel, id=0):
|
||||
self.UserId = id
|
||||
self.Name = name
|
||||
self.CityId = city.CityId if city is not None else 0
|
||||
@@ -13,7 +12,8 @@ class UserModel(TableABC):
|
||||
|
||||
@staticmethod
|
||||
def get_create_string() -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
CREATE TABLE IF NOT EXISTS `User` (
|
||||
`UserId` INT(30) NOT NULL AUTO_INCREMENT,
|
||||
`Name` VARCHAR(64) NOT NULL,
|
||||
@@ -21,30 +21,37 @@ class UserModel(TableABC):
|
||||
FOREIGN KEY (`UserId`) REFERENCES City(`CityId`),
|
||||
PRIMARY KEY(`UserId`)
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `User` (
|
||||
`Name`
|
||||
) VALUES (
|
||||
'{self.Name}'
|
||||
);
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `User`
|
||||
SET `Name` = '{self.Name}',
|
||||
`CityId` = {self.CityId},
|
||||
WHERE `UserId` = {self.UserId};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
return str(f"""
|
||||
return str(
|
||||
f"""
|
||||
DELETE FROM `User`
|
||||
WHERE `UserId` = {self.UserId};
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
@@ -7,36 +7,35 @@ from .user_repo_abc import UserRepoABC
|
||||
|
||||
|
||||
class UserRepo(UserRepoABC):
|
||||
|
||||
def __init__(self, db_context: DatabaseContextABC):
|
||||
UserRepoABC.__init__(self)
|
||||
|
||||
self._db_context: DatabaseContextABC = db_context
|
||||
|
||||
def add_test_user(self):
|
||||
city = CityModel('Haren', '49733')
|
||||
city2 = CityModel('Meppen', '49716')
|
||||
city = CityModel("Haren", "49733")
|
||||
city2 = CityModel("Meppen", "49716")
|
||||
self._db_context.cursor.execute(city2.insert_string)
|
||||
user = UserModel('TestUser', city)
|
||||
user = UserModel("TestUser", city)
|
||||
self._db_context.cursor.execute(user.insert_string)
|
||||
self._db_context.save_changes()
|
||||
|
||||
def get_users(self) -> list[UserModel]:
|
||||
users = []
|
||||
results = self._db_context.select('SELECT * FROM `User`')
|
||||
users = []
|
||||
results = self._db_context.select("SELECT * FROM `User`")
|
||||
for result in results:
|
||||
users.append(UserModel(result[1], self.get_city_by_id(result[2]), id = result[0]))
|
||||
users.append(UserModel(result[1], self.get_city_by_id(result[2]), id=result[0]))
|
||||
return users
|
||||
|
||||
def get_cities(self) -> list[CityModel]:
|
||||
cities = []
|
||||
results = self._db_context.select('SELECT * FROM `City`')
|
||||
cities = []
|
||||
results = self._db_context.select("SELECT * FROM `City`")
|
||||
for result in results:
|
||||
cities.append(CityModel(result[1], result[2], id = result[0]))
|
||||
cities.append(CityModel(result[1], result[2], id=result[0]))
|
||||
return cities
|
||||
|
||||
|
||||
def get_city_by_id(self, id: int) -> CityModel:
|
||||
if id is None:
|
||||
return None
|
||||
result = self._db_context.select(f'SELECT * FROM `City` WHERE `Id` = {id}')
|
||||
return CityModel(result[1], result[2], id = result[0])
|
||||
result = self._db_context.select(f"SELECT * FROM `City` WHERE `Id` = {id}")
|
||||
return CityModel(result[1], result[2], id=result[0])
|
||||
|
@@ -5,15 +5,18 @@ from .user_model import UserModel
|
||||
|
||||
|
||||
class UserRepoABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
def get_users(self) -> list[UserModel]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users(self) -> list[UserModel]: pass
|
||||
|
||||
def get_cities(self) -> list[CityModel]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_cities(self) -> list[CityModel]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_city_by_id(self, id: int) -> CityModel: pass
|
||||
def get_city_by_id(self, id: int) -> CityModel:
|
||||
pass
|
||||
|
@@ -1,8 +1,7 @@
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database import DatabaseSettings
|
||||
from cpl_core.dependency_injection import (ServiceCollectionABC,
|
||||
ServiceProviderABC)
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC, ServiceProviderABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_core.logging import Logger, LoggerABC
|
||||
|
||||
@@ -12,25 +11,28 @@ from model.user_repo_abc import UserRepoABC
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
|
||||
self._configuration = None
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironmentABC) -> ConfigurationABC:
|
||||
configuration.add_environment_variables('PYTHON_')
|
||||
configuration.add_environment_variables('CPL_')
|
||||
def configure_configuration(
|
||||
self, configuration: ConfigurationABC, environment: ApplicationEnvironmentABC
|
||||
) -> ConfigurationABC:
|
||||
configuration.add_environment_variables("PYTHON_")
|
||||
configuration.add_environment_variables("CPL_")
|
||||
configuration.parse_console_arguments()
|
||||
configuration.add_json_file(f'appsettings.json')
|
||||
configuration.add_json_file(f'appsettings.{configuration.environment.environment_name}.json')
|
||||
configuration.add_json_file(f'appsettings.{configuration.environment.host_name}.json', optional=True)
|
||||
configuration.add_json_file(f"appsettings.json")
|
||||
configuration.add_json_file(f"appsettings.{configuration.environment.environment_name}.json")
|
||||
configuration.add_json_file(f"appsettings.{configuration.environment.host_name}.json", optional=True)
|
||||
|
||||
self._configuration = configuration
|
||||
|
||||
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironmentABC) -> ServiceProviderABC:
|
||||
def configure_services(
|
||||
self, services: ServiceCollectionABC, environment: ApplicationEnvironmentABC
|
||||
) -> ServiceProviderABC:
|
||||
# Create and connect to database
|
||||
db_settings: DatabaseSettings = self._configuration.get_configuration(DatabaseSettings)
|
||||
services.add_db_context(DBContext, db_settings)
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -11,7 +11,6 @@ from di.tester import Tester
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
@@ -24,20 +23,20 @@ class Application(ApplicationABC):
|
||||
|
||||
def main(self):
|
||||
with self._services.create_scope() as scope:
|
||||
Console.write_line('Scope1')
|
||||
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')
|
||||
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')
|
||||
Console.write_line("Global")
|
||||
self._part_of_scoped()
|
||||
StaticTest.test()
|
||||
|
||||
|
@@ -3,10 +3,9 @@ from di.test_service import TestService
|
||||
|
||||
|
||||
class DITesterService:
|
||||
|
||||
def __init__(self, ts: TestService):
|
||||
self._ts = ts
|
||||
|
||||
|
||||
def run(self):
|
||||
Console.write_line('DIT: ')
|
||||
Console.write_line("DIT: ")
|
||||
self._ts.run()
|
||||
|
@@ -10,5 +10,5 @@ def main():
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@@ -11,19 +11,22 @@ from di.tester import Tester
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
def configure_configuration(
|
||||
self, configuration: ConfigurationABC, environment: ApplicationEnvironment
|
||||
) -> ConfigurationABC:
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
def configure_services(
|
||||
self, services: ServiceCollectionABC, environment: ApplicationEnvironment
|
||||
) -> 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_service_provider()
|
||||
|
@@ -4,7 +4,6 @@ from di.test_service import TestService
|
||||
|
||||
|
||||
class StaticTest:
|
||||
|
||||
@staticmethod
|
||||
@ServiceProvider.inject
|
||||
def test(services: ServiceProviderABC, config: ConfigurationABC, t1: TestService):
|
||||
|
@@ -5,9 +5,8 @@ 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}')
|
||||
Console.write_line(f"Im {self._name}")
|
||||
|
@@ -5,9 +5,8 @@ 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}')
|
||||
Console.write_line(f"Im {self._name}")
|
||||
|
@@ -2,9 +2,8 @@ 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}>'
|
||||
return f"<{type(self).__name__} {self._name}>"
|
||||
|
@@ -5,9 +5,8 @@ from cpl_core.utils.string import String
|
||||
|
||||
|
||||
class TestService:
|
||||
|
||||
def __init__(self):
|
||||
self._name = String.random_string(string.ascii_lowercase, 8)
|
||||
|
||||
def run(self):
|
||||
Console.write_line(f'Im {self._name}')
|
||||
Console.write_line(f"Im {self._name}")
|
||||
|
@@ -3,7 +3,6 @@ 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("Tester:")
|
||||
Console.write_line(t1, t2, t3)
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -11,16 +11,16 @@ discord-bot
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'discord_bot'
|
||||
__author__ = ''
|
||||
__license__ = ''
|
||||
__copyright__ = 'Copyright (c) '
|
||||
__version__ = '0.0.0'
|
||||
__title__ = "discord_bot"
|
||||
__author__ = ""
|
||||
__license__ = ""
|
||||
__copyright__ = "Copyright (c) "
|
||||
__version__ = "0.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='0', micro='0')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="0", micro="0")
|
||||
|
@@ -10,7 +10,6 @@ from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
|
||||
|
||||
|
||||
class Application(DiscordBotApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
@@ -23,18 +22,18 @@ class Application(DiscordBotApplicationABC):
|
||||
|
||||
async def main(self):
|
||||
try:
|
||||
self._logger.debug(__name__, f'Starting...\n')
|
||||
self._logger.trace(__name__, f'Try to start {DiscordBotService.__name__}')
|
||||
self._logger.debug(__name__, f"Starting...\n")
|
||||
self._logger.trace(__name__, f"Try to start {DiscordBotService.__name__}")
|
||||
await self._bot.start_async()
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, 'Start failed', e)
|
||||
self._logger.error(__name__, "Start failed", e)
|
||||
|
||||
async def stop_async(self):
|
||||
try:
|
||||
self._logger.trace(__name__, f'Try to stop {DiscordBotService.__name__}')
|
||||
self._logger.trace(__name__, f"Try to stop {DiscordBotService.__name__}")
|
||||
await self._bot.close()
|
||||
self._logger.trace(__name__, f'Stopped {DiscordBotService.__name__}')
|
||||
self._logger.trace(__name__, f"Stopped {DiscordBotService.__name__}")
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, 'stop failed', e)
|
||||
self._logger.error(__name__, "stop failed", e)
|
||||
|
||||
Console.write_line()
|
||||
|
@@ -8,7 +8,6 @@ from discord_bot.startup import Startup
|
||||
|
||||
|
||||
class Program:
|
||||
|
||||
def __init__(self):
|
||||
self._app: Optional[Application] = None
|
||||
|
||||
@@ -22,7 +21,7 @@ class Program:
|
||||
await self._app.stop_async()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
program = Program()
|
||||
try:
|
||||
asyncio.run(program.main())
|
||||
|
@@ -12,18 +12,21 @@ from modules.hello_world.purge_command import PurgeCommand
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
configuration.add_json_file('appsettings.json', optional=False)
|
||||
configuration.add_environment_variables('CPL_')
|
||||
configuration.add_environment_variables('DISCORD_')
|
||||
def configure_configuration(
|
||||
self, configuration: ConfigurationABC, environment: ApplicationEnvironment
|
||||
) -> ConfigurationABC:
|
||||
configuration.add_json_file("appsettings.json", optional=False)
|
||||
configuration.add_environment_variables("CPL_")
|
||||
configuration.add_environment_variables("DISCORD_")
|
||||
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
def configure_services(
|
||||
self, services: ServiceCollectionABC, environment: ApplicationEnvironment
|
||||
) -> ServiceProviderABC:
|
||||
services.add_logging()
|
||||
services.add_discord()
|
||||
dc_collection = get_discord_collection(services)
|
||||
|
@@ -11,16 +11,16 @@ discord-bot
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'modules.hello_world'
|
||||
__author__ = ''
|
||||
__license__ = ''
|
||||
__copyright__ = 'Copyright (c) '
|
||||
__version__ = '0.0.0'
|
||||
__title__ = "modules.hello_world"
|
||||
__author__ = ""
|
||||
__license__ = ""
|
||||
__copyright__ = "Copyright (c) "
|
||||
__version__ = "0.0.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='0', micro='0')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="0", minor="0", micro="0")
|
||||
|
@@ -6,32 +6,33 @@ from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
|
||||
|
||||
|
||||
class OnReadyEvent(OnReadyABC):
|
||||
|
||||
def __init__(self, logger: LoggerABC, bot: DiscordBotServiceABC):
|
||||
OnReadyABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
|
||||
def _log(self, _t: str, _o: object, _type: type = None):
|
||||
self._logger.debug(__name__, f'{_t} {_o} {_type}')
|
||||
self._logger.debug(__name__, f"{_t} {_o} {_type}")
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.info(__name__, 'Hello World')
|
||||
self._logger.info(__name__, "Hello World")
|
||||
for g in self._bot.guilds:
|
||||
self._log('-Guild', g, type(g))
|
||||
self._log("-Guild", g, type(g))
|
||||
for r in g.roles:
|
||||
self._log('--Role', r, type(r))
|
||||
self._log("--Role", r, type(r))
|
||||
for rm in r.members:
|
||||
self._log('---Rolemember', rm, type(rm))
|
||||
self._log("---Rolemember", rm, type(rm))
|
||||
|
||||
for m in g.members:
|
||||
self._log('--Member', m, type(m))
|
||||
self._log("--Member", m, type(m))
|
||||
for mr in m.roles:
|
||||
self._log('--Memberole', mr, type(mr))
|
||||
self._log("--Memberole", mr, type(mr))
|
||||
for rm in mr.members:
|
||||
self._log('---Rolemember', rm, type(rm))
|
||||
self._log("---Rolemember", rm, type(rm))
|
||||
|
||||
select = self._bot.guilds.select(lambda guild: (guild.name, guild.id))
|
||||
self._logger.warn(__name__, f'Does cpl.query select work? {select}')
|
||||
select_many = self._bot.guilds.select_many(lambda guild: guild.roles).where(lambda role: role.name == "Tester").first()
|
||||
self._logger.warn(__name__, f'Does cpl.query select_many work? {select_many}')
|
||||
self._logger.warn(__name__, f"Does cpl.query select work? {select}")
|
||||
select_many = (
|
||||
self._bot.guilds.select_many(lambda guild: guild.roles).where(lambda role: role.name == "Tester").first()
|
||||
)
|
||||
self._logger.warn(__name__, f"Does cpl.query select_many work? {select_many}")
|
||||
|
@@ -3,10 +3,9 @@ from cpl_discord.events.on_ready_abc import OnReadyABC
|
||||
|
||||
|
||||
class OnReadyTestEvent(OnReadyABC):
|
||||
|
||||
def __init__(self, logger: LoggerABC):
|
||||
OnReadyABC.__init__(self)
|
||||
self._logger = logger
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.info(__name__, 'Test second on ready')
|
||||
self._logger.info(__name__, "Test second on ready")
|
||||
|
@@ -7,22 +7,21 @@ from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
|
||||
|
||||
|
||||
class PingCommand(DiscordCommandABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
|
||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||
self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}")
|
||||
|
||||
@commands.hybrid_command()
|
||||
async def ping(self, ctx: Context):
|
||||
self._logger.debug(__name__, f'Received command ping {ctx}')
|
||||
self._logger.info(__name__, f'Bot name {self._bot.user.name}')
|
||||
self._logger.trace(__name__, f'Finished ping command')
|
||||
await ctx.send('Pong')
|
||||
self._logger.debug(__name__, f"Received command ping {ctx}")
|
||||
self._logger.info(__name__, f"Bot name {self._bot.user.name}")
|
||||
self._logger.trace(__name__, f"Finished ping command")
|
||||
await ctx.send("Pong")
|
||||
|
@@ -7,25 +7,24 @@ from cpl_discord.service.discord_bot_service_abc import DiscordBotServiceABC
|
||||
|
||||
|
||||
class PurgeCommand(DiscordCommandABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
|
||||
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||
self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}")
|
||||
|
||||
@commands.hybrid_command()
|
||||
async def purge(self, ctx: Context):
|
||||
self._logger.debug(__name__, f'Received command ping {ctx}')
|
||||
self._logger.info(__name__, f'Bot name {self._bot.user.name}')
|
||||
self._logger.trace(__name__, f'Finished ping command')
|
||||
self._logger.debug(__name__, f"Received command ping {ctx}")
|
||||
self._logger.info(__name__, f"Bot name {self._bot.user.name}")
|
||||
self._logger.trace(__name__, f"Finished ping command")
|
||||
await ctx.channel.purge()
|
||||
if ctx.interaction is None:
|
||||
return
|
||||
await ctx.interaction.response.send_message('Purged this channel xD')
|
||||
await ctx.interaction.response.send_message("Purged this channel xD")
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -1,10 +1,7 @@
|
||||
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Custom(GenerateSchematicABC):
|
||||
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
@@ -20,8 +17,4 @@ class Custom(GenerateSchematicABC):
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(
|
||||
cls,
|
||||
'custom',
|
||||
['cm', 'CM']
|
||||
)
|
||||
GenerateSchematicABC.register(cls, "custom", ["cm", "CM"])
|
||||
|
@@ -12,7 +12,6 @@ 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
|
||||
@@ -20,12 +19,12 @@ class Application(ApplicationABC):
|
||||
|
||||
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'
|
||||
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
|
||||
@@ -39,23 +38,23 @@ class Application(ApplicationABC):
|
||||
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')
|
||||
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(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)
|
||||
Console.write_line("scope", scope)
|
||||
with self._services.create_scope() as s:
|
||||
Console.write_line('with scope', s)
|
||||
Console.write_line("with scope", s)
|
||||
self.test_send_mail()
|
||||
|
@@ -11,16 +11,16 @@ sh-edraft Common Python library
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'general.arguments'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1'
|
||||
__title__ = "general.arguments"
|
||||
__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='04', micro='01')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2021", minor="04", micro="01")
|
||||
|
@@ -4,12 +4,11 @@ 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.error("Generate:")
|
||||
Console.write_line(args, self._env.environment_name)
|
||||
|
@@ -3,9 +3,8 @@ 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)
|
||||
Console.write_line("Install:", args)
|
||||
|
@@ -11,16 +11,16 @@ sh-edraft Common Python library
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'general.db'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1'
|
||||
__title__ = "general.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='04', micro='01')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2021", minor="04", micro="01")
|
||||
|
@@ -15,5 +15,5 @@ def main():
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@@ -7,25 +7,32 @@ 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'])
|
||||
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)
|
||||
services.add_transient(GenerateArgument).add_singleton(InstallArgument)
|
||||
|
@@ -9,16 +9,15 @@ 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)
|
||||
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
|
||||
|
||||
|
@@ -5,9 +5,8 @@ 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')
|
||||
Console.write_line("Hello World from App Extension")
|
||||
|
@@ -4,13 +4,11 @@ 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)
|
||||
Console.write_line("Hello World!", self._provider)
|
||||
ip = [192, 168, 178, 30]
|
||||
Console.write_line(ip, self._ip_pipe.transform(ip))
|
||||
|
@@ -6,12 +6,11 @@ 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')
|
||||
Console.write_line("config")
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
Console.write_line('services')
|
||||
Console.write_line("services")
|
||||
|
@@ -1,4 +1,3 @@
|
||||
class Custom:
|
||||
|
||||
def __init__(self):
|
||||
print('hello')
|
||||
print("hello")
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -8,7 +8,6 @@ from cpl_translation.translation_settings import TranslationSettings
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
@@ -17,13 +16,13 @@ class Application(ApplicationABC):
|
||||
self._translation_settings: TranslationSettings = config.get_configuration(TranslationSettings)
|
||||
|
||||
self._translation.load_by_settings(config.get_configuration(TranslationSettings))
|
||||
self._translation.set_default_lang('de')
|
||||
self._translation.set_default_lang("de")
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
|
||||
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'))
|
||||
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"))
|
||||
|
@@ -10,5 +10,5 @@ def main():
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@@ -5,14 +5,17 @@ from cpl_core.environment import ApplicationEnvironment
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
configuration.add_json_file('appsettings.json')
|
||||
def configure_configuration(
|
||||
self, configuration: ConfigurationABC, environment: ApplicationEnvironment
|
||||
) -> ConfigurationABC:
|
||||
configuration.add_json_file("appsettings.json")
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
def configure_services(
|
||||
self, services: ServiceCollectionABC, environment: ApplicationEnvironment
|
||||
) -> ServiceProviderABC:
|
||||
services.add_translation()
|
||||
return services.build_service_provider()
|
||||
|
Reference in New Issue
Block a user