Compare commits
No commits in common. "50201346e2bd9543f3e2e9dce6c43d496fd14d62" and "5b59d1d38474b1bb06b7e97415d620a1c8e528df" have entirely different histories.
50201346e2
...
5b59d1d384
@ -54,7 +54,6 @@ class ApplicationBuilder(ApplicationBuilderABC):
|
|||||||
|
|
||||||
config = self._configuration
|
config = self._configuration
|
||||||
services = self._services.build_service_provider()
|
services = self._services.build_service_provider()
|
||||||
config.resolve_runnable_argument_types(services)
|
|
||||||
|
|
||||||
for ex in self._app_extensions:
|
for ex in self._app_extensions:
|
||||||
extension = ex()
|
extension = ex()
|
||||||
|
@ -8,10 +8,8 @@ from cpl_core.configuration.configuration_abc import ConfigurationABC
|
|||||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||||
from cpl_core.configuration.configuration_variable_name_enum import ConfigurationVariableNameEnum
|
from cpl_core.configuration.configuration_variable_name_enum import ConfigurationVariableNameEnum
|
||||||
from cpl_core.configuration.console_argument import ConsoleArgument
|
from cpl_core.configuration.console_argument import ConsoleArgument
|
||||||
from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC
|
|
||||||
from cpl_core.console.console import Console
|
from cpl_core.console.console import Console
|
||||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
|
||||||
from cpl_core.environment.application_environment import ApplicationEnvironment
|
from cpl_core.environment.application_environment import ApplicationEnvironment
|
||||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||||
from cpl_core.environment.environment_name_enum import EnvironmentNameEnum
|
from cpl_core.environment.environment_name_enum import EnvironmentNameEnum
|
||||||
@ -380,15 +378,8 @@ class Configuration(ConfigurationABC):
|
|||||||
def add_configuration(self, key_type: Union[str, type], value: ConfigurationModelABC):
|
def add_configuration(self, key_type: Union[str, type], value: ConfigurationModelABC):
|
||||||
self._config[key_type] = value
|
self._config[key_type] = value
|
||||||
|
|
||||||
def create_console_argument(self, token: str, name: str, aliases: list[str], value_token: str,
|
|
||||||
is_value_token_optional: bool = None,
|
|
||||||
runnable: Type[RunnableArgumentABC] = None) -> ConsoleArgument:
|
|
||||||
argument = ConsoleArgument(token, name, aliases, value_token, is_value_token_optional, runnable)
|
|
||||||
self.add_console_argument(argument)
|
|
||||||
return argument
|
|
||||||
|
|
||||||
def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> \
|
def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> \
|
||||||
Optional[Union[str, ConfigurationModelABC]]:
|
Union[str, ConfigurationModelABC]:
|
||||||
if type(search_type) is str:
|
if type(search_type) is str:
|
||||||
if search_type == ConfigurationVariableNameEnum.environment.value:
|
if search_type == ConfigurationVariableNameEnum.environment.value:
|
||||||
return self._application_environment.environment_name
|
return self._application_environment.environment_name
|
||||||
@ -405,7 +396,3 @@ class Configuration(ConfigurationABC):
|
|||||||
for config_model in self._config:
|
for config_model in self._config:
|
||||||
if config_model == search_type:
|
if config_model == search_type:
|
||||||
return self._config[config_model]
|
return self._config[config_model]
|
||||||
|
|
||||||
def resolve_runnable_argument_types(self, services: ServiceProviderABC):
|
|
||||||
for arg in self._argument_types:
|
|
||||||
arg.set_runnable(services.get_service(arg.runnable_type))
|
|
||||||
|
@ -4,7 +4,6 @@ from typing import Type, Union, Optional
|
|||||||
|
|
||||||
from cpl_core.configuration.console_argument import ConsoleArgument
|
from cpl_core.configuration.console_argument import ConsoleArgument
|
||||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||||
from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC
|
|
||||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||||
|
|
||||||
|
|
||||||
@ -95,35 +94,7 @@ class ConfigurationABC(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def create_console_argument(self, token: str, name: str, aliases: list[str], value_token: str,
|
def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> Union[str, ConfigurationModelABC]:
|
||||||
is_value_token_optional: bool = None,
|
|
||||||
runnable: Type[RunnableArgumentABC] = None) -> ConsoleArgument:
|
|
||||||
r"""Creates and adds a console argument to known console arguments
|
|
||||||
|
|
||||||
Parameter
|
|
||||||
---------
|
|
||||||
token: :class:`str`
|
|
||||||
Specifies optional beginning of argument
|
|
||||||
name :class:`str`
|
|
||||||
Specifies name of argument
|
|
||||||
aliases list[:class:`str`]
|
|
||||||
Specifies possible aliases of name
|
|
||||||
value_token :class:`str`
|
|
||||||
Specifies were the value begins
|
|
||||||
is_value_token_optional :class:`bool`
|
|
||||||
Specifies if values are optional
|
|
||||||
runnable: :class:`cpl_core.configuration.console_argument.ConsoleArgument`
|
|
||||||
Specifies class to run when called if value is not None
|
|
||||||
|
|
||||||
Returns
|
|
||||||
------
|
|
||||||
Object of :class:`cpl_core.configuration.console_argument.ConsoleArgument`
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> Union[
|
|
||||||
str, ConfigurationModelABC]:
|
|
||||||
r"""Returns value from configuration by given type
|
r"""Returns value from configuration by given type
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
@ -136,14 +107,3 @@ class ConfigurationABC(ABC):
|
|||||||
Object of Union[:class:`str`, :class:`cpl_core.configuration.configuration_model_abc.ConfigurationModelABC`]
|
Object of Union[:class:`str`, :class:`cpl_core.configuration.configuration_model_abc.ConfigurationModelABC`]
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def resolve_runnable_argument_types(self, services: 'ServiceProviderABC'):
|
|
||||||
r"""Gets all objects for given types of ConsoleArguments
|
|
||||||
|
|
||||||
Parameter
|
|
||||||
---------
|
|
||||||
services: :class:`cpl_core.dependency_injection.service_provider_abc.ServiceProviderABC`
|
|
||||||
Provides services
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
from typing import Type, Optional
|
|
||||||
|
|
||||||
from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC
|
|
||||||
|
|
||||||
|
|
||||||
class ConsoleArgument:
|
class ConsoleArgument:
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
@ -11,7 +6,6 @@ class ConsoleArgument:
|
|||||||
aliases: list[str],
|
aliases: list[str],
|
||||||
value_token: str,
|
value_token: str,
|
||||||
is_value_token_optional: bool = None,
|
is_value_token_optional: bool = None,
|
||||||
runnable: Type[RunnableArgumentABC] = None,
|
|
||||||
console_arguments: list['ConsoleArgument'] = None
|
console_arguments: list['ConsoleArgument'] = None
|
||||||
):
|
):
|
||||||
r"""Representation of an console argument
|
r"""Representation of an console argument
|
||||||
@ -23,7 +17,6 @@ class ConsoleArgument:
|
|||||||
aliases: list[:class:`str`]
|
aliases: list[:class:`str`]
|
||||||
value_token: :class:`str`
|
value_token: :class:`str`
|
||||||
is_value_token_optional: :class:`bool`
|
is_value_token_optional: :class:`bool`
|
||||||
runnable: :class:`cpl_core.configuration.console_argument.ConsoleArgument`
|
|
||||||
console_arguments: List[:class:`cpl_core.configuration.console_argument.ConsoleArgument`]
|
console_arguments: List[:class:`cpl_core.configuration.console_argument.ConsoleArgument`]
|
||||||
"""
|
"""
|
||||||
self._token = token
|
self._token = token
|
||||||
@ -31,9 +24,7 @@ class ConsoleArgument:
|
|||||||
self._aliases = aliases
|
self._aliases = aliases
|
||||||
self._value_token = value_token
|
self._value_token = value_token
|
||||||
self._is_value_token_optional = is_value_token_optional
|
self._is_value_token_optional = is_value_token_optional
|
||||||
self._console_arguments = console_arguments if console_arguments is not None else []
|
self._console_arguments = console_arguments
|
||||||
self._runnable_type = runnable
|
|
||||||
self._runnable: Optional[RunnableArgumentABC] = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def token(self) -> str:
|
def token(self) -> str:
|
||||||
@ -58,42 +49,3 @@ class ConsoleArgument:
|
|||||||
@property
|
@property
|
||||||
def console_arguments(self) -> list['ConsoleArgument']:
|
def console_arguments(self) -> list['ConsoleArgument']:
|
||||||
return self._console_arguments
|
return self._console_arguments
|
||||||
|
|
||||||
@property
|
|
||||||
def runnable_type(self) -> Type[RunnableArgumentABC]:
|
|
||||||
return self._runnable_type
|
|
||||||
|
|
||||||
def set_runnable(self, runnable: RunnableArgumentABC):
|
|
||||||
self._runnable = runnable
|
|
||||||
|
|
||||||
def add_console_argument(self, token: str, name: str, aliases: list[str], value_token: str,
|
|
||||||
is_value_token_optional: bool = None) -> 'ConsoleArgument':
|
|
||||||
r"""Creates and adds a console argument to known console arguments
|
|
||||||
|
|
||||||
Parameter
|
|
||||||
---------
|
|
||||||
token: :class:`str`
|
|
||||||
Specifies optional beginning of argument
|
|
||||||
name :class:`str`
|
|
||||||
Specifies name of argument
|
|
||||||
aliases list[:class:`str`]
|
|
||||||
Specifies possible aliases of name
|
|
||||||
value_token :class:`str`
|
|
||||||
Specifies were the value begins
|
|
||||||
is_value_token_optional :class:`bool`
|
|
||||||
Specifies if values are optional
|
|
||||||
|
|
||||||
Returns
|
|
||||||
------
|
|
||||||
self :class:`cpl_core.configuration.console_argument.ConsoleArgument` not created argument!
|
|
||||||
"""
|
|
||||||
argument = ConsoleArgument(token, name, aliases, value_token, is_value_token_optional)
|
|
||||||
self._console_arguments.append(argument)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def run(self, args: list[str]):
|
|
||||||
r"""Executes runnable if exists
|
|
||||||
"""
|
|
||||||
if self._runnable is None:
|
|
||||||
return
|
|
||||||
self._runnable.run(args)
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
from abc import ABC, abstractmethod
|
|
||||||
|
|
||||||
|
|
||||||
class RunnableArgumentABC(ABC):
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def __init__(self): pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def run(self, args: list[str]): pass
|
|
@ -10,6 +10,7 @@ from cpl_core.dependency_injection.service_lifetime_enum import ServiceLifetimeE
|
|||||||
from cpl_core.dependency_injection.service_provider import ServiceProvider
|
from cpl_core.dependency_injection.service_provider import ServiceProvider
|
||||||
from cpl_core.logging.logger_service import Logger
|
from cpl_core.logging.logger_service import Logger
|
||||||
from cpl_core.logging.logger_abc import LoggerABC
|
from cpl_core.logging.logger_abc import LoggerABC
|
||||||
|
from cpl_core.utils.credential_manager import CredentialManager
|
||||||
|
|
||||||
|
|
||||||
class ServiceCollection(ServiceCollectionABC):
|
class ServiceCollection(ServiceCollectionABC):
|
||||||
@ -58,15 +59,12 @@ class ServiceCollection(ServiceCollectionABC):
|
|||||||
|
|
||||||
self._add_descriptor(impl, ServiceLifetimeEnum.singleton)
|
self._add_descriptor(impl, ServiceLifetimeEnum.singleton)
|
||||||
|
|
||||||
return self
|
|
||||||
|
|
||||||
def add_scoped(self, service_type: Type, service: Callable = None):
|
def add_scoped(self, service_type: Type, service: Callable = None):
|
||||||
if service is not None:
|
if service is not None:
|
||||||
self._add_descriptor(service, ServiceLifetimeEnum.scoped)
|
self._add_descriptor(service, ServiceLifetimeEnum.scoped)
|
||||||
else:
|
else:
|
||||||
self._add_descriptor(service_type, ServiceLifetimeEnum.scoped)
|
self._add_descriptor(service_type, ServiceLifetimeEnum.scoped)
|
||||||
|
|
||||||
return self
|
|
||||||
|
|
||||||
def add_transient(self, service_type: type, service: type = None):
|
def add_transient(self, service_type: type, service: type = None):
|
||||||
if service is not None:
|
if service is not None:
|
||||||
@ -74,7 +72,5 @@ class ServiceCollection(ServiceCollectionABC):
|
|||||||
else:
|
else:
|
||||||
self._add_descriptor(service_type, ServiceLifetimeEnum.transient)
|
self._add_descriptor(service_type, ServiceLifetimeEnum.transient)
|
||||||
|
|
||||||
return self
|
|
||||||
|
|
||||||
def build_service_provider(self) -> ServiceProviderABC:
|
def build_service_provider(self) -> ServiceProviderABC:
|
||||||
return ServiceProvider(self._service_descriptors, self._configuration, self._database_context)
|
return ServiceProvider(self._service_descriptors, self._configuration, self._database_context)
|
||||||
|
@ -31,7 +31,7 @@ class ServiceCollectionABC(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_transient(self, service_type: Type, service: Callable = None) -> 'ServiceCollectionABC':
|
def add_transient(self, service_type: Type, service: Callable = None):
|
||||||
r"""Adds a service with transient lifetime
|
r"""Adds a service with transient lifetime
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
@ -40,15 +40,11 @@ class ServiceCollectionABC(ABC):
|
|||||||
Type of the service
|
Type of the service
|
||||||
service: :class:`Callable`
|
service: :class:`Callable`
|
||||||
Object of the service
|
Object of the service
|
||||||
|
|
||||||
Returns
|
|
||||||
------
|
|
||||||
self: :class:`cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_scoped(self, service_type: Type, service: Callable = None) -> 'ServiceCollectionABC':
|
def add_scoped(self, service_type: Type, service: Callable = None):
|
||||||
r"""Adds a service with scoped lifetime
|
r"""Adds a service with scoped lifetime
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
@ -57,15 +53,11 @@ class ServiceCollectionABC(ABC):
|
|||||||
Type of the service
|
Type of the service
|
||||||
service: :class:`Callable`
|
service: :class:`Callable`
|
||||||
Object of the service
|
Object of the service
|
||||||
|
|
||||||
Returns
|
|
||||||
------
|
|
||||||
self: :class:`cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_singleton(self, service_type: Type, service: Callable = None) -> 'ServiceCollectionABC':
|
def add_singleton(self, service_type: Type, service: Callable = None):
|
||||||
r"""Adds a service with singleton lifetime
|
r"""Adds a service with singleton lifetime
|
||||||
|
|
||||||
Parameter
|
Parameter
|
||||||
@ -74,10 +66,6 @@ class ServiceCollectionABC(ABC):
|
|||||||
Type of the service
|
Type of the service
|
||||||
service: :class:`Callable`
|
service: :class:`Callable`
|
||||||
Object of the service
|
Object of the service
|
||||||
|
|
||||||
Returns
|
|
||||||
------
|
|
||||||
self: :class:`cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC
|
|
||||||
from cpl_core.console import Console
|
|
||||||
|
|
||||||
|
|
||||||
class GenerateArgument(RunnableArgumentABC):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
RunnableArgumentABC.__init__(self)
|
|
||||||
|
|
||||||
def run(self, args: list[str]):
|
|
||||||
Console.write_line('Generate:', args)
|
|
@ -1,11 +0,0 @@
|
|||||||
from cpl_core.configuration.runnable_argument_abc import RunnableArgumentABC
|
|
||||||
from cpl_core.console import Console
|
|
||||||
|
|
||||||
|
|
||||||
class InstallArgument(RunnableArgumentABC):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
RunnableArgumentABC.__init__(self)
|
|
||||||
|
|
||||||
def run(self, args: list[str]):
|
|
||||||
Console.write_line('Install:', args)
|
|
@ -3,13 +3,11 @@ from cpl_core.application import ApplicationBuilder
|
|||||||
from test_extension import TestExtension
|
from test_extension import TestExtension
|
||||||
from startup import Startup
|
from startup import Startup
|
||||||
from test_startup_extension import TestStartupExtension
|
from test_startup_extension import TestStartupExtension
|
||||||
from parameter_startup import ParameterStartup
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app_builder = ApplicationBuilder(Application)
|
app_builder = ApplicationBuilder(Application)
|
||||||
app_builder.use_startup(Startup)
|
app_builder.use_startup(Startup)
|
||||||
app_builder.use_extension(ParameterStartup)
|
|
||||||
app_builder.use_extension(TestStartupExtension)
|
app_builder.use_extension(TestStartupExtension)
|
||||||
app_builder.use_extension(TestExtension)
|
app_builder.use_extension(TestExtension)
|
||||||
app_builder.build().run()
|
app_builder.build().run()
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
from cpl_core.application import StartupExtensionABC
|
|
||||||
from cpl_core.configuration import ConfigurationABC
|
|
||||||
from cpl_core.dependency_injection import ServiceCollectionABC
|
|
||||||
from cpl_core.environment import ApplicationEnvironmentABC
|
|
||||||
from arguments.generate_argument import GenerateArgument
|
|
||||||
from arguments.install_argument import InstallArgument
|
|
||||||
|
|
||||||
|
|
||||||
class ParameterStartup(StartupExtensionABC):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
StartupExtensionABC.__init__(self)
|
|
||||||
|
|
||||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
|
||||||
config.create_console_argument('', 'generate', ['g', 'G'], '', runnable=GenerateArgument) \
|
|
||||||
.add_console_argument('', 'abc', ['a', 'A'], ' ') \
|
|
||||||
.add_console_argument('', 'class', ['c', 'C'], ' ') \
|
|
||||||
.add_console_argument('', 'enum', ['e', 'E'], ' ') \
|
|
||||||
.add_console_argument('', 'service', ['s', 'S'], ' ') \
|
|
||||||
.add_console_argument('', 'settings', ['st', 'ST'], ' ') \
|
|
||||||
.add_console_argument('', 'thread', ['t', 'T'], ' ') \
|
|
||||||
.add_console_argument('-', 'o', ['o', 'O'], '=')
|
|
||||||
config.create_console_argument('', 'install', ['i', 'I'], ' ', is_value_token_optional=True,
|
|
||||||
runnable=InstallArgument) \
|
|
||||||
.add_console_argument('--', 'virtual', ['v', 'V'], '') \
|
|
||||||
.add_console_argument('--', 'simulate', ['s', 'S'], '')
|
|
||||||
|
|
||||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
|
||||||
services \
|
|
||||||
.add_singleton(GenerateArgument) \
|
|
||||||
.add_singleton(InstallArgument)
|
|
Loading…
Reference in New Issue
Block a user