Refactored code
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
include ../ README
|
||||
recursive-include sh_edraft *.txt
|
@@ -1,66 +0,0 @@
|
||||
{
|
||||
"TimeFormatSettings": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
"LoggingSettings": {
|
||||
"Path": "../build/logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "INFO",
|
||||
"FileLogLevel": "TRACE"
|
||||
},
|
||||
"PublishSettings": {
|
||||
"SourcePath": "./",
|
||||
"DistPath": "../build/dist",
|
||||
"Templates": [
|
||||
{
|
||||
"TemplatePath": "../publish_templates/all_template.txt",
|
||||
"Name": "all",
|
||||
"Description": "",
|
||||
"LongDescription": "",
|
||||
"CopyrightDate": "2020",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": ", see LICENSE for more details.",
|
||||
"Title": "",
|
||||
"Author": "Sven Heidemann",
|
||||
"Version": {
|
||||
"Major": 2020,
|
||||
"Minor": 12,
|
||||
"Micro": 10
|
||||
}
|
||||
},
|
||||
{
|
||||
"TemplatePath": "../publish_templates/all_template.txt",
|
||||
"Name": "sh_edraft",
|
||||
"Description": "common python library",
|
||||
"LongDescription": "Library to share common classes and models used at sh-edraft.de",
|
||||
"CopyrightDate": "2020",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": ", see LICENSE for more details.",
|
||||
"Title": "",
|
||||
"Author": "Sven Heidemann",
|
||||
"Version": {
|
||||
"Major": 2020,
|
||||
"Minor": 12,
|
||||
"Micro": 10
|
||||
}
|
||||
}
|
||||
],
|
||||
"IncludedFiles": [
|
||||
"./MANIFEST.in",
|
||||
"../LICENSE",
|
||||
"../README.md",
|
||||
"../requirements.txt",
|
||||
"sh_edraft/cli/cpl_cli/templates"
|
||||
],
|
||||
"ExcludedFiles": [
|
||||
"./tests",
|
||||
"./tests_dev"
|
||||
],
|
||||
"TemplateEnding": "_template.txt"
|
||||
}
|
||||
}
|
32
src/cpl/application/application_abc.py
Normal file
32
src/cpl/application/application_abc.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Type, Optional
|
||||
|
||||
from cpl.application.application_host_abc import ApplicationHostABC
|
||||
from cpl.application.startup_abc import StartupABC
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.dependency_injection.service_provider_base import ServiceProviderABC
|
||||
|
||||
|
||||
class ApplicationABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
self._startup: Optional[StartupABC] = None
|
||||
self._app_host: Optional[ApplicationHostABC] = None
|
||||
self._services: Optional[ServiceProviderABC] = None
|
||||
self._configuration: Optional[ConfigurationABC] = None
|
||||
|
||||
def use_startup(self, startup: Type[StartupABC]):
|
||||
self._startup = startup()
|
||||
|
||||
def build(self):
|
||||
if self._startup is None:
|
||||
print('Startup is empty')
|
||||
exit()
|
||||
|
||||
self._app_host = self._startup.create_application_host()
|
||||
self._configuration = self._startup.create_configuration()
|
||||
self._services = self._startup.create_services()
|
||||
|
||||
@abstractmethod
|
||||
def run(self): pass
|
42
src/cpl/application/application_host.py
Normal file
42
src/cpl/application/application_host.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import atexit
|
||||
from datetime import datetime
|
||||
|
||||
from cpl.application.application_host_abc import ApplicationHostABC
|
||||
from cpl.application.application_runtime import ApplicationRuntime
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
from cpl.configuration.configuration import Configuration
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.dependency_injection.service_provider import ServiceProvider
|
||||
from cpl.dependency_injection.service_provider_base import ServiceProviderABC
|
||||
|
||||
|
||||
class ApplicationHost(ApplicationHostABC):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationHostABC.__init__(self)
|
||||
|
||||
# Init
|
||||
self._config = Configuration()
|
||||
self._app_runtime = ApplicationRuntime(self._config)
|
||||
self._services = ServiceProvider(self._app_runtime)
|
||||
|
||||
# Set vars
|
||||
self._start_time: datetime = datetime.now()
|
||||
self._end_time: datetime = datetime.now()
|
||||
|
||||
atexit.register(Console.close)
|
||||
|
||||
@property
|
||||
def configuration(self) -> ConfigurationABC:
|
||||
return self._config
|
||||
|
||||
@property
|
||||
def application_runtime(self) -> ApplicationRuntimeABC:
|
||||
return self._app_runtime
|
||||
|
||||
@property
|
||||
def services(self) -> ServiceProviderABC:
|
||||
return self._services
|
||||
|
||||
def create(self): pass
|
23
src/cpl/application/application_host_abc.py
Normal file
23
src/cpl/application/application_host_abc.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.dependency_injection.service_provider_base import ServiceProviderABC
|
||||
|
||||
|
||||
class ApplicationHostABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def configuration(self) -> ConfigurationABC: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def application_runtime(self) -> ApplicationRuntimeABC: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def services(self) -> ServiceProviderABC: pass
|
@@ -1,20 +1,20 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||
from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
|
||||
|
||||
class ApplicationRuntime(ApplicationRuntimeBase):
|
||||
class ApplicationRuntime(ApplicationRuntimeABC):
|
||||
|
||||
def __init__(self, config: ConfigurationBase):
|
||||
ApplicationRuntimeBase.__init__(self)
|
||||
def __init__(self, config: ConfigurationABC):
|
||||
ApplicationRuntimeABC.__init__(self)
|
||||
|
||||
self._app_configuration = config
|
||||
self._start_time: datetime = datetime.now()
|
||||
self._end_time: datetime = datetime.now()
|
||||
|
||||
@property
|
||||
def configuration(self) -> ConfigurationBase:
|
||||
def configuration(self) -> ConfigurationABC:
|
||||
return self._app_configuration
|
||||
|
||||
@property
|
@@ -1,17 +1,17 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
|
||||
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
|
||||
|
||||
class ApplicationRuntimeBase(ABC):
|
||||
class ApplicationRuntimeABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def configuration(self) -> ConfigurationBase: pass
|
||||
def configuration(self) -> ConfigurationABC: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
20
src/cpl/application/startup_abc.py
Normal file
20
src/cpl/application/startup_abc.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl.application.application_host_abc import ApplicationHostABC
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.dependency_injection.service_provider_base import ServiceProviderABC
|
||||
|
||||
|
||||
class StartupABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def create_application_host(self) -> ApplicationHostABC: pass
|
||||
|
||||
@abstractmethod
|
||||
def create_configuration(self) -> ConfigurationABC: pass
|
||||
|
||||
@abstractmethod
|
||||
def create_services(self) -> ServiceProviderABC: pass
|
@@ -2,26 +2,26 @@ import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||
from sh_edraft.configuration.model.configuration_variable_name import ConfigurationVariableName
|
||||
from sh_edraft.environment.base.environment_base import EnvironmentBase
|
||||
from sh_edraft.environment.hosting_environment import HostingEnvironment
|
||||
from sh_edraft.environment.model.environment_name import EnvironmentName
|
||||
from sh_edraft.console.console import Console
|
||||
from sh_edraft.console.model import ForegroundColor
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.configuration.configuration_variable_name import ConfigurationVariableName
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color import ForegroundColor
|
||||
from cpl.environment.hosting_environment import HostingEnvironment
|
||||
from cpl.environment.environment_abc import EnvironmentABC
|
||||
from cpl.environment.environment_name import EnvironmentName
|
||||
|
||||
|
||||
class Configuration(ConfigurationBase):
|
||||
class Configuration(ConfigurationABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationBase.__init__(self)
|
||||
ConfigurationABC.__init__(self)
|
||||
|
||||
self._hosting_environment = HostingEnvironment()
|
||||
self._config: dict[type, ConfigurationModelBase] = {}
|
||||
self._config: dict[type, ConfigurationModelABC] = {}
|
||||
|
||||
@property
|
||||
def environment(self) -> EnvironmentBase:
|
||||
def environment(self) -> EnvironmentABC:
|
||||
return self._hosting_environment
|
||||
|
||||
@staticmethod
|
||||
@@ -87,7 +87,7 @@ class Configuration(ConfigurationBase):
|
||||
return None
|
||||
|
||||
config_from_file = self._load_json_file(file_path)
|
||||
for sub in ConfigurationModelBase.__subclasses__():
|
||||
for sub in ConfigurationModelABC.__subclasses__():
|
||||
for key, value in config_from_file.items():
|
||||
if sub.__name__ == key:
|
||||
configuration = sub()
|
||||
@@ -106,16 +106,13 @@ class Configuration(ConfigurationBase):
|
||||
self._print_error(__name__, f'Cannot load config file: {file}! -> {e}')
|
||||
return {}
|
||||
|
||||
def add_configuration(self, key_type: type, value: ConfigurationModelBase):
|
||||
def add_configuration(self, key_type: type, value: ConfigurationModelABC):
|
||||
self._config[key_type] = value
|
||||
|
||||
def get_configuration(self, search_type: type) -> ConfigurationModelBase:
|
||||
def get_configuration(self, search_type: type) -> ConfigurationModelABC:
|
||||
if search_type not in self._config:
|
||||
raise Exception(f'Config model by type {search_type} not found')
|
||||
|
||||
for config_model in self._config:
|
||||
if config_model == search_type:
|
||||
return self._config[config_model]
|
||||
|
||||
def create(self):
|
||||
pass
|
@@ -2,18 +2,18 @@ from abc import abstractmethod, ABC
|
||||
from collections import Callable
|
||||
from typing import Type
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.environment.base.environment_base import EnvironmentBase
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.environment.environment_abc import EnvironmentABC
|
||||
|
||||
|
||||
class ConfigurationBase(ABC):
|
||||
class ConfigurationABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def environment(self) -> EnvironmentBase: pass
|
||||
def environment(self) -> EnvironmentABC: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_environment_variables(self, prefix: str): pass
|
||||
@@ -28,7 +28,4 @@ class ConfigurationBase(ABC):
|
||||
def add_configuration(self, key_type: type, value: object): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_configuration(self, search_type: Type[ConfigurationModelBase]) -> Callable[ConfigurationModelBase]: pass
|
||||
|
||||
@abstractmethod
|
||||
def create(self): pass
|
||||
def get_configuration(self, search_type: Type[ConfigurationModelABC]) -> Callable[ConfigurationModelABC]: pass
|
@@ -1,7 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class ConfigurationModelBase(ABC):
|
||||
class ConfigurationModelABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
@@ -5,8 +5,8 @@ import pyfiglet
|
||||
from tabulate import tabulate
|
||||
from termcolor import colored
|
||||
|
||||
from sh_edraft.console.model.background_color import BackgroundColor
|
||||
from sh_edraft.console.model.foreground_color import ForegroundColor
|
||||
from cpl.console.background_color import BackgroundColor
|
||||
from cpl.console.foreground_color import ForegroundColor
|
||||
|
||||
|
||||
class Console:
|
0
src/cpl/database/__init__.py
Normal file
0
src/cpl/database/__init__.py
Normal file
0
src/cpl/database/connection/__init__.py
Normal file
0
src/cpl/database/connection/__init__.py
Normal file
@@ -3,16 +3,16 @@ from typing import Optional
|
||||
from sqlalchemy import engine, create_engine
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from sh_edraft.database.connection.base.database_connection_base import DatabaseConnectionBase
|
||||
from sh_edraft.database.model.database_settings import DatabaseSettings
|
||||
from sh_edraft.console.console import Console
|
||||
from sh_edraft.console.model.foreground_color import ForegroundColor
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color import ForegroundColor
|
||||
from cpl.database.connection.database_connection_abc import DatabaseConnectionABC
|
||||
from cpl.database.database_settings import DatabaseSettings
|
||||
|
||||
|
||||
class DatabaseConnection(DatabaseConnectionBase):
|
||||
class DatabaseConnection(DatabaseConnectionABC):
|
||||
|
||||
def __init__(self, database_settings: DatabaseSettings):
|
||||
DatabaseConnectionBase.__init__(self)
|
||||
DatabaseConnectionABC.__init__(self)
|
||||
|
||||
self._db_settings = database_settings
|
||||
|
||||
@@ -32,6 +32,9 @@ class DatabaseConnection(DatabaseConnectionBase):
|
||||
try:
|
||||
self._engine = create_engine(connection_string)
|
||||
|
||||
if self._db_settings.auth_plugin is not None:
|
||||
self._engine = create_engine(connection_string, connect_args={'auth_plugin': self._db_settings.auth_plugin})
|
||||
|
||||
if self._db_settings.encoding is not None:
|
||||
self._engine.encoding = self._db_settings.encoding
|
||||
|
||||
@@ -53,4 +56,3 @@ class DatabaseConnection(DatabaseConnectionBase):
|
||||
Console.write_line(f'[{__name__}] Database connection failed -> {e}')
|
||||
Console.set_foreground_color(ForegroundColor.default)
|
||||
exit()
|
||||
|
@@ -4,7 +4,7 @@ from sqlalchemy import engine
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
class DatabaseConnectionBase(ABC):
|
||||
class DatabaseConnectionABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
0
src/cpl/database/context/__init__.py
Normal file
0
src/cpl/database/context/__init__.py
Normal file
@@ -1,21 +1,21 @@
|
||||
from sqlalchemy import engine, Table
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from sh_edraft.database.connection.database_connection import DatabaseConnection
|
||||
from sh_edraft.database.connection.base.database_connection_base import DatabaseConnectionBase
|
||||
from sh_edraft.database.context.base.database_context_base import DatabaseContextBase
|
||||
from sh_edraft.database.model.dbmodel import DBModel
|
||||
from sh_edraft.database.model.database_settings import DatabaseSettings
|
||||
from sh_edraft.console.console import Console
|
||||
from sh_edraft.console.model.foreground_color import ForegroundColor
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color import ForegroundColor
|
||||
from cpl.database.connection.database_connection import DatabaseConnection
|
||||
from cpl.database.connection.database_connection_abc import DatabaseConnectionABC
|
||||
from cpl.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl.database.database_settings import DatabaseSettings
|
||||
from cpl.database.database_model import DatabaseModel
|
||||
|
||||
|
||||
class DatabaseContext(DatabaseContextBase):
|
||||
class DatabaseContext(DatabaseContextABC):
|
||||
|
||||
def __init__(self, database_settings: DatabaseSettings):
|
||||
DatabaseContextBase.__init__(self)
|
||||
DatabaseContextABC.__init__(self)
|
||||
|
||||
self._db: DatabaseConnectionBase = DatabaseConnection(database_settings)
|
||||
self._db: DatabaseConnectionABC = DatabaseConnection(database_settings)
|
||||
self._tables: list[Table] = []
|
||||
|
||||
@property
|
||||
@@ -35,11 +35,11 @@ class DatabaseContext(DatabaseContextBase):
|
||||
|
||||
def _create_tables(self):
|
||||
try:
|
||||
for subclass in DBModel.__subclasses__():
|
||||
for subclass in DatabaseModel.__subclasses__():
|
||||
self._tables.append(subclass.__table__)
|
||||
|
||||
DBModel.metadata.drop_all(self._db.engine, self._tables)
|
||||
DBModel.metadata.create_all(self._db.engine, self._tables, checkfirst=True)
|
||||
DatabaseModel.metadata.drop_all(self._db.engine, self._tables)
|
||||
DatabaseModel.metadata.create_all(self._db.engine, self._tables, checkfirst=True)
|
||||
Console.set_foreground_color(ForegroundColor.green)
|
||||
Console.write_line(f'[{__name__}] Created tables')
|
||||
Console.set_foreground_color(ForegroundColor.default)
|
@@ -1,16 +1,10 @@
|
||||
from abc import abstractmethod
|
||||
from abc import abstractmethod, ABC
|
||||
|
||||
from sqlalchemy import engine
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from sh_edraft.service.base.service_base import ServiceBase
|
||||
|
||||
|
||||
class DatabaseContextBase(ServiceBase):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
ServiceBase.__init__(self)
|
||||
class DatabaseContextABC(ABC):
|
||||
|
||||
@property
|
||||
@abstractmethod
|
@@ -1,3 +1,3 @@
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
DBModel: declarative_base = declarative_base()
|
||||
DatabaseModel: declarative_base = declarative_base()
|
@@ -1,35 +1,44 @@
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.database.model.database_settings_name import DatabaseSettingsName
|
||||
from sh_edraft.console.console import Console
|
||||
from sh_edraft.console.model.foreground_color import ForegroundColor
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color import ForegroundColor
|
||||
from cpl.database.database_settings_name import DatabaseSettingsName
|
||||
|
||||
|
||||
class DatabaseSettings(ConfigurationModelBase):
|
||||
class DatabaseSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelBase.__init__(self)
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._auth_plugin: Optional[str] = None
|
||||
self._connection_string: Optional[str] = None
|
||||
self._credentials: Optional[str] = None
|
||||
self._encoding: Optional[str] = None
|
||||
self._case_sensitive: Optional[bool] = None
|
||||
self._echo: Optional[bool] = None
|
||||
|
||||
|
||||
@property
|
||||
def auth_plugin(self) -> str:
|
||||
return self._auth_plugin
|
||||
|
||||
@auth_plugin.setter
|
||||
def auth_plugin(self, auth_plugin: str):
|
||||
self._auth_plugin = auth_plugin
|
||||
|
||||
@property
|
||||
def connection_string(self) -> str:
|
||||
return self._connection_string
|
||||
|
||||
|
||||
@connection_string.setter
|
||||
def connection_string(self, connection_string: str):
|
||||
self._connection_string = connection_string
|
||||
|
||||
|
||||
@property
|
||||
def credentials(self) -> str:
|
||||
return self._credentials
|
||||
|
||||
|
||||
@credentials.setter
|
||||
def credentials(self, credentials: str):
|
||||
self._credentials = credentials
|
||||
@@ -63,6 +72,9 @@ class DatabaseSettings(ConfigurationModelBase):
|
||||
self._connection_string = settings[DatabaseSettingsName.connection_string.value]
|
||||
self._credentials = settings[DatabaseSettingsName.credentials.value]
|
||||
|
||||
if DatabaseSettingsName.auth_plugin.value in settings:
|
||||
self._auth_plugin = settings[DatabaseSettingsName.auth_plugin.value]
|
||||
|
||||
if DatabaseSettingsName.encoding.value in settings:
|
||||
self._encoding = settings[DatabaseSettingsName.encoding.value]
|
||||
|
@@ -8,3 +8,4 @@ class DatabaseSettingsName(Enum):
|
||||
encoding = 'Encoding'
|
||||
case_sensitive = 'CaseSensitive'
|
||||
echo = 'Echo'
|
||||
auth_plugin = 'AuthPlugin'
|
0
src/cpl/dependency_injection/__init__.py
Normal file
0
src/cpl/dependency_injection/__init__.py
Normal file
@@ -1,10 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class $Name(ABC):
|
||||
class ServiceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def create(self): pass
|
@@ -1,71 +1,71 @@
|
||||
from abc import ABC
|
||||
from collections import Callable
|
||||
from inspect import signature, Parameter
|
||||
from typing import Type, Optional
|
||||
from typing import Type, Optional, Union
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.database.context.base.database_context_base import DatabaseContextBase
|
||||
from sh_edraft.environment.base import EnvironmentBase
|
||||
from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase
|
||||
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase
|
||||
from sh_edraft.service.base.service_base import ServiceBase
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl.dependency_injection.service_abc import ServiceABC
|
||||
from cpl.dependency_injection.service_provider_base import ServiceProviderABC
|
||||
from cpl.environment.environment_abc import EnvironmentABC
|
||||
|
||||
|
||||
class ServiceProvider(ServiceProviderBase):
|
||||
class ServiceProvider(ServiceProviderABC):
|
||||
|
||||
def __init__(self, app_runtime: ApplicationRuntimeBase):
|
||||
ServiceProviderBase.__init__(self)
|
||||
self._app_runtime: ApplicationRuntimeBase = app_runtime
|
||||
self._database_context: Optional[DatabaseContextBase] = None
|
||||
def __init__(self, app_runtime: ApplicationRuntimeABC):
|
||||
ServiceProviderABC.__init__(self)
|
||||
self._app_runtime: ApplicationRuntimeABC = app_runtime
|
||||
self._database_context: Optional[DatabaseContextABC] = None
|
||||
|
||||
self._transient_services: dict[Type[ServiceBase], Type[ServiceBase]] = {}
|
||||
self._scoped_services: dict[Type[ServiceBase], Type[ServiceBase]] = {}
|
||||
self._singleton_services: dict[Type[ServiceBase], ServiceBase] = {}
|
||||
self._transient_services: dict[Type[ServiceABC], Type[ServiceABC]] = {}
|
||||
self._scoped_services: dict[Type[ServiceABC], Type[ServiceABC]] = {}
|
||||
self._singleton_services: dict[Type[ServiceABC], Callable[ServiceABC], ServiceABC] = {}
|
||||
|
||||
def create(self): pass
|
||||
|
||||
def _create_instance(self, service: Callable[ServiceBase]) -> ServiceBase:
|
||||
def _create_instance(self, service: Union[Callable[ServiceABC], ServiceABC]) -> Callable[ServiceABC]:
|
||||
sig = signature(service.__init__)
|
||||
params = []
|
||||
for param in sig.parameters.items():
|
||||
parameter = param[1]
|
||||
if parameter.name != 'self' and parameter.annotation != Parameter.empty:
|
||||
if issubclass(parameter.annotation, ApplicationRuntimeBase):
|
||||
if issubclass(parameter.annotation, ApplicationRuntimeABC):
|
||||
params.append(self._app_runtime)
|
||||
|
||||
elif issubclass(parameter.annotation, EnvironmentBase):
|
||||
elif issubclass(parameter.annotation, EnvironmentABC):
|
||||
params.append(self._app_runtime.configuration.environment)
|
||||
|
||||
elif issubclass(parameter.annotation, DatabaseContextBase):
|
||||
elif issubclass(parameter.annotation, DatabaseContextABC):
|
||||
params.append(self._database_context)
|
||||
|
||||
elif issubclass(parameter.annotation, ServiceBase):
|
||||
params.append(self.get_service(parameter.annotation))
|
||||
|
||||
elif issubclass(parameter.annotation, ConfigurationModelBase):
|
||||
elif issubclass(parameter.annotation, ConfigurationModelABC):
|
||||
params.append(self._app_runtime.configuration.get_configuration(parameter.annotation))
|
||||
|
||||
else:
|
||||
params.append(self.get_service(parameter.annotation))
|
||||
|
||||
return service(*params)
|
||||
|
||||
def add_db_context(self, db_context: Type[DatabaseContextBase]):
|
||||
def add_db_context(self, db_context: Type[DatabaseContextABC]):
|
||||
self._database_context = self._create_instance(db_context)
|
||||
|
||||
def get_db_context(self) -> Callable[DatabaseContextBase]:
|
||||
def get_db_context(self) -> Callable[DatabaseContextABC]:
|
||||
return self._database_context
|
||||
|
||||
def add_transient(self, service_type: Type[ServiceBase], service: Type[ServiceBase]):
|
||||
def add_transient(self, service_type: Type[ServiceABC], service: Type[ServiceABC]):
|
||||
self._transient_services[service_type] = service
|
||||
|
||||
def add_scoped(self, service_type: Type[ServiceBase], service: Type[ServiceBase]):
|
||||
def add_scoped(self, service_type: Type[ServiceABC], service: Type[ServiceABC]):
|
||||
self._scoped_services[service_type] = service
|
||||
|
||||
def add_singleton(self, service_type: Type[ServiceBase], service: Callable[ServiceBase]):
|
||||
def add_singleton(self, service_type: Type[ServiceABC], service: Callable[ServiceABC]):
|
||||
for known_service in self._singleton_services:
|
||||
if type(known_service) == service_type:
|
||||
raise Exception(f'Service with type {service_type} already exists')
|
||||
|
||||
self._singleton_services[service_type] = self._create_instance(service)
|
||||
|
||||
def get_service(self, instance_type: Type[ServiceBase]) -> Callable[ServiceBase]:
|
||||
def get_service(self, instance_type: Type) -> Callable[ServiceABC]:
|
||||
for service in self._transient_services:
|
||||
if service == instance_type and isinstance(self._transient_services[service], type(instance_type)):
|
||||
return self._create_instance(self._transient_services[service])
|
||||
@@ -78,7 +78,7 @@ class ServiceProvider(ServiceProviderBase):
|
||||
if service == instance_type and isinstance(self._singleton_services[service], instance_type):
|
||||
return self._singleton_services[service]
|
||||
|
||||
def remove_service(self, instance_type: Type[ServiceBase]):
|
||||
def remove_service(self, instance_type: Type[ServiceABC]):
|
||||
for service in self._transient_services:
|
||||
if service == instance_type and isinstance(self._transient_services[service], type(instance_type)):
|
||||
del self._transient_services[service]
|
33
src/cpl/dependency_injection/service_provider_base.py
Normal file
33
src/cpl/dependency_injection/service_provider_base.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from abc import abstractmethod, ABC
|
||||
from collections import Callable
|
||||
from typing import Type
|
||||
|
||||
from cpl.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl.dependency_injection.service_abc import ServiceABC
|
||||
|
||||
|
||||
class ServiceProviderABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def add_db_context(self, db_context: Type[DatabaseContextABC]): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_db_context(self) -> Callable[DatabaseContextABC]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_transient(self, service_type: Type, service: Type): pass
|
||||
|
||||
@abstractmethod
|
||||
def add_scoped(self, service_type: Type, service: Type): pass
|
||||
|
||||
@abstractmethod
|
||||
def add_singleton(self, service_type: Type, service: Callable): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_service(self, instance_type: Type) -> Callable[ServiceABC]: pass
|
||||
|
||||
@abstractmethod
|
||||
def remove_service(self, instance_type: type): pass
|
0
src/cpl/environment/__init__.py
Normal file
0
src/cpl/environment/__init__.py
Normal file
@@ -1,7 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class EnvironmentBase(ABC):
|
||||
class EnvironmentABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
@@ -1,14 +1,14 @@
|
||||
from socket import gethostname
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.environment.base.environment_base import EnvironmentBase
|
||||
from sh_edraft.environment.model.environment_name import EnvironmentName
|
||||
from cpl.environment.environment_abc import EnvironmentABC
|
||||
from cpl.environment.environment_name import EnvironmentName
|
||||
|
||||
|
||||
class HostingEnvironment(EnvironmentBase):
|
||||
class HostingEnvironment(EnvironmentABC):
|
||||
|
||||
def __init__(self, name: EnvironmentName = EnvironmentName.production, crp: str = './'):
|
||||
EnvironmentBase.__init__(self)
|
||||
EnvironmentABC.__init__(self)
|
||||
|
||||
self._environment_name: Optional[EnvironmentName] = name
|
||||
self._app_name: Optional[str] = None
|
0
src/cpl/logging/__init__.py
Normal file
0
src/cpl/logging/__init__.py
Normal file
@@ -3,19 +3,19 @@ import os
|
||||
import traceback
|
||||
from string import Template
|
||||
|
||||
from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase
|
||||
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||
from sh_edraft.logging.model.logging_settings import LoggingSettings
|
||||
from sh_edraft.logging.model.logging_level import LoggingLevel
|
||||
from sh_edraft.time.model.time_format_settings import TimeFormatSettings
|
||||
from sh_edraft.console.console import Console
|
||||
from sh_edraft.console.model.foreground_color import ForegroundColor
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color import ForegroundColor
|
||||
from cpl.logging.logger_abc import LoggerABC
|
||||
from cpl.logging.logging_level import LoggingLevel
|
||||
from cpl.logging.logging_settings import LoggingSettings
|
||||
from cpl.time.time_format_settings import TimeFormatSettings
|
||||
|
||||
|
||||
class Logger(LoggerBase):
|
||||
class Logger(LoggerABC):
|
||||
|
||||
def __init__(self, logging_settings: LoggingSettings, time_format: TimeFormatSettings, app_runtime: ApplicationRuntimeBase):
|
||||
LoggerBase.__init__(self)
|
||||
def __init__(self, logging_settings: LoggingSettings, time_format: TimeFormatSettings, app_runtime: ApplicationRuntimeABC):
|
||||
LoggerABC.__init__(self)
|
||||
|
||||
self._app_runtime = app_runtime
|
||||
self._log_settings: LoggingSettings = logging_settings
|
@@ -1,13 +1,13 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from sh_edraft.service.base.service_base import ServiceBase
|
||||
from cpl.dependency_injection.service_abc import ServiceABC
|
||||
|
||||
|
||||
class LoggerBase(ServiceBase):
|
||||
class LoggerABC(ServiceABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
ServiceBase.__init__(self)
|
||||
ServiceABC.__init__(self)
|
||||
|
||||
@abstractmethod
|
||||
def header(self, string: str): pass
|
@@ -1,17 +1,17 @@
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.logging.model.logging_settings_name import LoggingSettingsName
|
||||
from sh_edraft.logging.model.logging_level import LoggingLevel
|
||||
from sh_edraft.console.console import Console
|
||||
from sh_edraft.console.model.foreground_color import ForegroundColor
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color import ForegroundColor
|
||||
from cpl.logging.logging_level import LoggingLevel
|
||||
from cpl.logging.logging_settings_name import LoggingSettingsName
|
||||
|
||||
|
||||
class LoggingSettings(ConfigurationModelBase):
|
||||
class LoggingSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelBase.__init__(self)
|
||||
ConfigurationModelABC.__init__(self)
|
||||
self._path: Optional[str] = None
|
||||
self._filename: Optional[str] = None
|
||||
self._console: Optional[LoggingLevel] = None
|
0
src/cpl/mailing/__init__.py
Normal file
0
src/cpl/mailing/__init__.py
Normal file
@@ -2,19 +2,18 @@ import ssl
|
||||
from smtplib import SMTP
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.environment.base.environment_base import EnvironmentBase
|
||||
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||
from sh_edraft.mailing.base.email_client_base import EMailClientBase
|
||||
from sh_edraft.mailing.model.email import EMail
|
||||
from sh_edraft.mailing.model.email_client_settings import EMailClientSettings
|
||||
from sh_edraft.service.base.service_base import ServiceBase
|
||||
from sh_edraft.utils.credential_manager import CredentialManager
|
||||
from cpl.environment.environment_abc import EnvironmentABC
|
||||
from cpl.logging.logger_abc import LoggerABC
|
||||
from cpl.mailing.email import EMail
|
||||
from cpl.mailing.email_client_abc import EMailClientABC
|
||||
from cpl.mailing.email_client_settings import EMailClientSettings
|
||||
from cpl.utils.credential_manager import CredentialManager
|
||||
|
||||
|
||||
class EMailClient(EMailClientBase):
|
||||
class EMailClient(EMailClientABC):
|
||||
|
||||
def __init__(self, environment: EnvironmentBase, logger: LoggerBase, mail_settings: EMailClientSettings):
|
||||
ServiceBase.__init__(self)
|
||||
def __init__(self, environment: EnvironmentABC, logger: LoggerABC, mail_settings: EMailClientSettings):
|
||||
EMailClientABC.__init__(self)
|
||||
|
||||
self._environment = environment
|
||||
self._mail_settings = mail_settings
|
@@ -1,14 +1,14 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from sh_edraft.mailing.model.email import EMail
|
||||
from sh_edraft.service.base.service_base import ServiceBase
|
||||
from cpl.dependency_injection.service_abc import ServiceABC
|
||||
from cpl.mailing.email import EMail
|
||||
|
||||
|
||||
class EMailClientBase(ServiceBase):
|
||||
class EMailClientABC(ServiceABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
ServiceBase.__init__(self)
|
||||
ServiceABC.__init__(self)
|
||||
|
||||
@abstractmethod
|
||||
def connect(self): pass
|
@@ -1,14 +1,14 @@
|
||||
import traceback
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.console.console import Console
|
||||
from sh_edraft.mailing.model.email_client_settings_name import EMailClientSettingsName
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.mailing.email_client_settings_name import EMailClientSettingsName
|
||||
|
||||
|
||||
class EMailClientSettings(ConfigurationModelBase):
|
||||
class EMailClientSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelBase.__init__(self)
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._host: str = ''
|
||||
self._port: int = 0
|
0
src/cpl/time/__init__.py
Normal file
0
src/cpl/time/__init__.py
Normal file
@@ -1,16 +1,16 @@
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.time.model.time_format_settings_names import TimeFormatSettingsNames
|
||||
from sh_edraft.console.console import Console
|
||||
from sh_edraft.console.model.foreground_color import ForegroundColor
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color import ForegroundColor
|
||||
from cpl.time.time_format_settings_names import TimeFormatSettingsNames
|
||||
|
||||
|
||||
class TimeFormatSettings(ConfigurationModelBase):
|
||||
class TimeFormatSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelBase.__init__(self)
|
||||
ConfigurationModelABC.__init__(self)
|
||||
self._date_format: Optional[str] = None
|
||||
self._time_format: Optional[str] = None
|
||||
self._date_time_format: Optional[str] = None
|
0
src/cpl/utils/__init__.py
Normal file
0
src/cpl/utils/__init__.py
Normal file
0
src/cpl_cli/__init__.py
Normal file
0
src/cpl_cli/__init__.py
Normal file
29
src/setup.py
29
src/setup.py
@@ -1,29 +0,0 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
name='sh_edraft',
|
||||
version='2020.0.1',
|
||||
packages=setuptools.find_packages(exclude=["tests*"]),
|
||||
url='https://www.sh-edraft.de',
|
||||
license='MIT',
|
||||
author='Sven Heidemann',
|
||||
author_email='edraft.sh@gmail.com',
|
||||
include_package_data=True,
|
||||
description='sh-edraft python common lib',
|
||||
python_requires='>=3.8',
|
||||
install_requires=[
|
||||
'discord.py',
|
||||
'flask',
|
||||
'mysql-connector',
|
||||
'SQLAlchemy',
|
||||
'termcolor',
|
||||
'pyfiglet',
|
||||
'tabulate',
|
||||
'smtplib'
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'cpl = sh_edraft.cli.cpl_cli.cli:main'
|
||||
]
|
||||
}
|
||||
)
|
@@ -1,25 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft common python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Library to share common classes and models used at sh-edraft.de
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,25 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.cli
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.cli'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.10'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=10)
|
@@ -1,25 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.cli.command
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.cli.command'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.10'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=10)
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.cli.command.base
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.cli.command.base'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.10'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .command_base import CommandBase
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=10)
|
@@ -1,15 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class CommandBase(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
self._aliases: list[str] = []
|
||||
|
||||
@property
|
||||
def aliases(self):
|
||||
return self._aliases
|
||||
|
||||
@abstractmethod
|
||||
def run(self, args: list[str]): pass
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.cli.cpl_cli
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.cli.cpl_cli'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.10'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .cli import CLI
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=10)
|
@@ -1,42 +0,0 @@
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from sh_edraft.cli.cpl_cli.commands.build.build import Build
|
||||
from sh_edraft.cli.cpl_cli.commands.help import Help
|
||||
from sh_edraft.cli.cpl_cli.commands.new import New
|
||||
from sh_edraft.cli.cpl_cli.commands.publish.publish import Publish
|
||||
from sh_edraft.cli.cpl_cli.commands.version import Version
|
||||
from sh_edraft.cli.interpreter.interpreter import Interpreter
|
||||
from sh_edraft.console.console import Console
|
||||
|
||||
|
||||
class CLI:
|
||||
|
||||
def __init__(self):
|
||||
self._interpreter = Interpreter()
|
||||
|
||||
def setup(self):
|
||||
self._interpreter.add_command(Build())
|
||||
self._interpreter.add_command(Help())
|
||||
self._interpreter.add_command(New())
|
||||
self._interpreter.add_command(Publish())
|
||||
self._interpreter.add_command(Version())
|
||||
|
||||
def main(self):
|
||||
string = ' '.join(sys.argv[1:])
|
||||
try:
|
||||
self._interpreter.interpret(string)
|
||||
except Exception as e:
|
||||
tb = traceback.format_exc()
|
||||
Console.error(str(e), tb)
|
||||
Console.error('Run \'cpl help\'')
|
||||
|
||||
|
||||
def main():
|
||||
cli = CLI()
|
||||
cli.setup()
|
||||
cli.main()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.cli.cpl_cli.commands
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.cli.cpl_cli.commands'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.10'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .version import Version
|
||||
from .help import Help
|
||||
from .new import New
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=10)
|
@@ -1,27 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.cli.cpl_cli.commands.build
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.cli.cpl_cli.commands.build'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.10'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .app import BuildApp
|
||||
from .build import Build
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=10)
|
@@ -1,47 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||
from sh_edraft.hosting.application_host import ApplicationHost
|
||||
from sh_edraft.hosting.base.application_base import ApplicationBase
|
||||
from sh_edraft.logging.logger import Logger
|
||||
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||
from sh_edraft.publish.publisher import Publisher
|
||||
from sh_edraft.publish.base.publisher_base import PublisherBase
|
||||
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase
|
||||
|
||||
|
||||
class BuildApp(ApplicationBase):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationBase.__init__(self)
|
||||
|
||||
self._app_host: Optional[ApplicationHost] = None
|
||||
self._services: Optional[ServiceProviderBase] = None
|
||||
self._configuration: Optional[ConfigurationBase] = None
|
||||
self._logger: Optional[LoggerBase] = None
|
||||
self._publisher: Optional[PublisherBase] = None
|
||||
|
||||
def create_application_host(self):
|
||||
self._app_host = ApplicationHost()
|
||||
self._configuration = self._app_host.configuration
|
||||
self._services = self._app_host.services
|
||||
|
||||
def create_configuration(self):
|
||||
self._configuration.add_json_file(f'build.json')
|
||||
|
||||
def create_services(self):
|
||||
# Add and create logger
|
||||
self._services.add_singleton(LoggerBase, Logger)
|
||||
self._logger = self._services.get_service(LoggerBase)
|
||||
|
||||
# Add and create publisher
|
||||
self._services.add_singleton(PublisherBase, Publisher)
|
||||
self._publisher: Publisher = self._services.get_service(PublisherBase)
|
||||
|
||||
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._publisher.create()
|
||||
self._publisher.build()
|
@@ -1,23 +0,0 @@
|
||||
from sh_edraft.cli.command.base.command_base import CommandBase
|
||||
from sh_edraft.cli.cpl_cli.commands.build.app import BuildApp
|
||||
from sh_edraft.console.console import Console
|
||||
|
||||
|
||||
class Build(CommandBase):
|
||||
|
||||
def __init__(self):
|
||||
CommandBase.__init__(self)
|
||||
self._app = BuildApp()
|
||||
|
||||
self._aliases.append('-b')
|
||||
self._aliases.append('-B')
|
||||
|
||||
def run(self, args: list[str]):
|
||||
if len(args) > 0:
|
||||
Console.error(f'Invalid arguments {args}')
|
||||
Console.error('Run \'cpl help\'')
|
||||
|
||||
self._app.create_application_host()
|
||||
self._app.create_configuration()
|
||||
self._app.create_services()
|
||||
self._app.main()
|
@@ -1,27 +0,0 @@
|
||||
from sh_edraft.cli.command.base.command_base import CommandBase
|
||||
from sh_edraft.console.console import Console
|
||||
|
||||
|
||||
class Help(CommandBase):
|
||||
|
||||
def __init__(self):
|
||||
CommandBase.__init__(self)
|
||||
self._aliases.append('-h')
|
||||
self._aliases.append('-H')
|
||||
|
||||
def run(self, args: list[str]):
|
||||
Console.write_line('Available Commands:')
|
||||
commands = [
|
||||
['build (-b|-B)', 'Prepares files for publishing into an output directory named dist/ at the given output path. Must be executed from within a workspace directory.'],
|
||||
['help (-h|-H)', 'Lists available commands and their short descriptions.'],
|
||||
['new', 'Creates a new file or package.'],
|
||||
['publish (-p|-P)', 'Prepares files for publishing into an output directory named dist/ at the given output path and executes setup.py. Must be executed from within a workspace directory.'],
|
||||
['version (-v|-V)', 'Outputs CPL CLI version.']
|
||||
]
|
||||
for name, description in commands:
|
||||
Console.set_foreground_color('blue')
|
||||
Console.write(f'\n\t{name} ')
|
||||
Console.set_foreground_color('default')
|
||||
Console.write(f'{description}')
|
||||
|
||||
Console.write('\n')
|
@@ -1,97 +0,0 @@
|
||||
import os
|
||||
|
||||
from sh_edraft.cli.command.base.command_base import CommandBase
|
||||
from sh_edraft.console.console import Console
|
||||
|
||||
|
||||
class New(CommandBase):
|
||||
|
||||
def __init__(self):
|
||||
CommandBase.__init__(self)
|
||||
|
||||
def run(self, args: list[str]):
|
||||
rel_path = f'{os.path.dirname(__file__)}/../'
|
||||
if len(args) == 0:
|
||||
Console.error(f'Expected arguments {args}')
|
||||
Console.error('Run \'cpl help\'')
|
||||
return
|
||||
|
||||
elif len(args) != 2:
|
||||
Console.error(f'Invalid arguments {args}')
|
||||
Console.error('Run \'cpl help\'')
|
||||
return
|
||||
|
||||
if not os.path.isdir(f'{rel_path}/templates/{args[0]}'):
|
||||
Console.error(f'Unexpected argument {args[0]}')
|
||||
Console.error('Run \'cpl help\'')
|
||||
|
||||
sub_args = args[1:]
|
||||
|
||||
if len(sub_args) != 1:
|
||||
Console.error(f'Unexpected argument {sub_args[1]}')
|
||||
Console.error('Run \'cpl help\'')
|
||||
|
||||
if not (sub_args[0].startswith('.') or sub_args[0].startswith('/')):
|
||||
full_path = f'./{sub_args[0]}'
|
||||
else:
|
||||
full_path = sub_args[0]
|
||||
|
||||
name = os.path.basename(full_path)
|
||||
path = os.path.dirname(full_path)
|
||||
|
||||
if args[0] in ['base', 'class', 'configmodel', 'enum', 'service']:
|
||||
if not os.path.isdir(path):
|
||||
os.makedirs(path)
|
||||
else:
|
||||
if not os.path.isdir(full_path):
|
||||
os.makedirs(full_path)
|
||||
|
||||
for r, d, f in os.walk(f'{rel_path}/templates/{args[0]}'):
|
||||
for file in f:
|
||||
template_content = ''
|
||||
with open(f'{r}/{file}') as template:
|
||||
template_content = template.read()
|
||||
template.close()
|
||||
|
||||
file = file.replace('txt', 'py')
|
||||
if args[0] in ['base', 'class', 'configmodel', 'enum', 'service']:
|
||||
suffix = None
|
||||
|
||||
if args[0] == 'base':
|
||||
suffix = 'base'
|
||||
|
||||
elif args[0] == 'configmodel':
|
||||
suffix = 'settings'
|
||||
|
||||
elif args[0] == 'service':
|
||||
suffix = 'service'
|
||||
|
||||
if suffix is not None:
|
||||
file_path = f'{path}/{name}_{suffix}.py'
|
||||
else:
|
||||
file_path = f'{path}/{name}.py'
|
||||
else:
|
||||
file_path = f'{full_path}/{file}'
|
||||
|
||||
with open(file_path, 'w+') as pyfile:
|
||||
if name[0].islower():
|
||||
name = f'{name[0].upper()}{name[1:]}'
|
||||
|
||||
if args[0] == 'base':
|
||||
template_content = template_content.replace('$Name', f'{name}Base')
|
||||
pyfile.write(template_content)
|
||||
|
||||
elif args[0] == 'configmodel':
|
||||
template_content = template_content.replace('$Name', f'{name}Settings')
|
||||
pyfile.write(template_content)
|
||||
|
||||
elif args[0] == 'service':
|
||||
template_content = template_content.replace('$Name', f'{name}Service')
|
||||
template_content = template_content.replace('$Base', f'{name}Base')
|
||||
pyfile.write(template_content)
|
||||
|
||||
else:
|
||||
template_content = template_content.replace('$Name', name)
|
||||
pyfile.write(template_content)
|
||||
|
||||
pyfile.close()
|
@@ -1,27 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.cli.cpl_cli.commands.publish
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.cli.cpl_cli.commands.publish'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.10'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .app import PublishApp
|
||||
from .publish import Publish
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=10)
|
@@ -1,48 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||
from sh_edraft.hosting.application_host import ApplicationHost
|
||||
from sh_edraft.hosting.base.application_base import ApplicationBase
|
||||
from sh_edraft.logging.logger import Logger
|
||||
from sh_edraft.logging.base.logger_base import LoggerBase
|
||||
from sh_edraft.publish.publisher import Publisher
|
||||
from sh_edraft.publish.base.publisher_base import PublisherBase
|
||||
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase
|
||||
|
||||
|
||||
class PublishApp(ApplicationBase):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationBase.__init__(self)
|
||||
|
||||
self._app_host: Optional[ApplicationHost] = None
|
||||
self._services: Optional[ServiceProviderBase] = None
|
||||
self._configuration: Optional[ConfigurationBase] = None
|
||||
self._logger: Optional[LoggerBase] = None
|
||||
self._publisher: Optional[PublisherBase] = None
|
||||
|
||||
def create_application_host(self):
|
||||
self._app_host = ApplicationHost()
|
||||
self._configuration = self._app_host.configuration
|
||||
self._services = self._app_host.services
|
||||
|
||||
def create_configuration(self):
|
||||
self._configuration.add_json_file(f'build.json')
|
||||
|
||||
def create_services(self):
|
||||
# Add and create logger
|
||||
self._services.add_singleton(LoggerBase, Logger)
|
||||
self._logger = self._services.get_service(LoggerBase)
|
||||
|
||||
# Add and create publisher
|
||||
self._services.add_singleton(PublisherBase, Publisher)
|
||||
self._publisher: Publisher = self._services.get_service(PublisherBase)
|
||||
|
||||
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._publisher.create()
|
||||
self._publisher.build()
|
||||
self._publisher.publish()
|
@@ -1,23 +0,0 @@
|
||||
from sh_edraft.cli.command.base.command_base import CommandBase
|
||||
from sh_edraft.cli.cpl_cli.commands.publish.app import PublishApp
|
||||
from sh_edraft.console.console import Console
|
||||
|
||||
|
||||
class Publish(CommandBase):
|
||||
|
||||
def __init__(self):
|
||||
CommandBase.__init__(self)
|
||||
self._app = PublishApp()
|
||||
|
||||
self._aliases.append('-p')
|
||||
self._aliases.append('-P')
|
||||
|
||||
def run(self, args: list[str]):
|
||||
if len(args) > 0:
|
||||
Console.error(f'Invalid arguments {args}')
|
||||
Console.error('Run \'cpl help\'')
|
||||
|
||||
self._app.create_application_host()
|
||||
self._app.create_configuration()
|
||||
self._app.create_services()
|
||||
self._app.main()
|
@@ -1,42 +0,0 @@
|
||||
import pkgutil
|
||||
import sys
|
||||
import platform
|
||||
|
||||
import pkg_resources
|
||||
|
||||
import sh_edraft
|
||||
from sh_edraft import cli
|
||||
from sh_edraft.cli.command.base.command_base import CommandBase
|
||||
from sh_edraft.console.console import Console
|
||||
|
||||
|
||||
class Version(CommandBase):
|
||||
|
||||
def __init__(self):
|
||||
CommandBase.__init__(self)
|
||||
self._aliases.append('-v')
|
||||
self._aliases.append('-V')
|
||||
|
||||
def run(self, args: list[str]):
|
||||
Console.set_foreground_color('yellow')
|
||||
Console.banner('CPL CLI')
|
||||
Console.set_foreground_color('default')
|
||||
Console.write_line(f'Common Python Library CLI: {cli.__version__}')
|
||||
Console.write_line(f'Python: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')
|
||||
Console.write_line(f'OS: {platform.system()} {platform.processor()}')
|
||||
|
||||
Console.write_line('CPL:')
|
||||
packages = []
|
||||
for importer, modname, is_pkg in pkgutil.iter_modules(sh_edraft.__path__):
|
||||
module = importer.find_module(modname).load_module(modname)
|
||||
packages.append([f'{modname}', module.__version__])
|
||||
|
||||
Console.table(['Name', 'Version'], packages)
|
||||
|
||||
Console.write_line('\nPython Packages:')
|
||||
packages = []
|
||||
deps = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set)
|
||||
for p in deps:
|
||||
packages.append([p, deps[p]])
|
||||
|
||||
Console.table(['Name', 'Version'], packages)
|
@@ -1 +0,0 @@
|
||||
# imports:
|
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"TimeFormatSettings": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
"LoggingSettings": {
|
||||
"Path": "build/logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "INFO",
|
||||
"FileLogLevel": "INFO"
|
||||
},
|
||||
"PublishSettings": {
|
||||
"SourcePath": "./",
|
||||
"DistPath": "build/dist",
|
||||
"Templates": [],
|
||||
"IncludedFiles": [],
|
||||
"ExcludedFiles": [],
|
||||
"TemplateEnding": "_template.txt"
|
||||
}
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
from program import Program
|
||||
|
||||
if __name__ == '__main__':
|
||||
program = Program()
|
||||
program.create_application_host()
|
||||
program.create_configuration()
|
||||
program.create_services()
|
||||
program.main()
|
@@ -1,43 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.configuration.base import ConfigurationBase
|
||||
from sh_edraft.hosting import ApplicationHost
|
||||
from sh_edraft.hosting.base import ApplicationBase
|
||||
from sh_edraft.logging import Logger
|
||||
from sh_edraft.logging.base import LoggerBase
|
||||
from sh_edraft.service.providing.base import ServiceProviderBase
|
||||
|
||||
|
||||
class Program(ApplicationBase):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationBase.__init__(self)
|
||||
|
||||
self._app_host: Optional[ApplicationHost] = None
|
||||
self._services: Optional[ServiceProviderBase] = None
|
||||
self._configuration: Optional[ConfigurationBase] = None
|
||||
self._logger: Optional[LoggerBase] = None
|
||||
|
||||
def create_application_host(self):
|
||||
self._app_host = ApplicationHost()
|
||||
self._configuration = self._app_host.configuration
|
||||
self._services = self._app_host.services
|
||||
|
||||
def create_configuration(self):
|
||||
self._configuration.add_environment_variables('PYTHON_')
|
||||
self._configuration.add_environment_variables('CPL_')
|
||||
self._configuration.add_argument_variables()
|
||||
self._configuration.add_json_file(f'appsettings.json')
|
||||
self._configuration.add_json_file(f'appsettings.{self._configuration.environment.environment_name}.json', optional=True)
|
||||
self._configuration.add_json_file(f'appsettings.{self._configuration.environment.host_name}.json', optional=True)
|
||||
|
||||
def create_services(self):
|
||||
# Add and create logger
|
||||
self._services.add_singleton(LoggerBase, Logger)
|
||||
self._logger = self._services.get_service(LoggerBase)
|
||||
|
||||
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}')
|
@@ -1,4 +0,0 @@
|
||||
class $Name:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
@@ -1,20 +0,0 @@
|
||||
import traceback
|
||||
|
||||
from sh_edraft.configuration.base import ConfigurationModelBase
|
||||
from sh_edraft.console import Console
|
||||
from sh_edraft.console.model import ForegroundColor
|
||||
|
||||
|
||||
class $Name(ConfigurationModelBase):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelBase.__init__(self)
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
pass
|
||||
except Exception as e:
|
||||
Console.set_foreground_color(ForegroundColor.red)
|
||||
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
Console.set_foreground_color(ForegroundColor.default)
|
@@ -1,6 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class $Name(Enum):
|
||||
|
||||
pass
|
@@ -1,6 +0,0 @@
|
||||
class $Name($Base):
|
||||
|
||||
def __init__(self):
|
||||
TestBase.__init__(self)
|
||||
|
||||
self.create()
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.cli.interpreter
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.cli.interpreter'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.10'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .interpreter import Interpreter
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=10)
|
@@ -1,33 +0,0 @@
|
||||
from sh_edraft.cli.command.base.command_base import CommandBase
|
||||
from sh_edraft.console.console import Console
|
||||
|
||||
|
||||
class Interpreter:
|
||||
|
||||
def __init__(self):
|
||||
self._commands: list[CommandBase] = []
|
||||
|
||||
def add_command(self, command: CommandBase):
|
||||
self._commands.append(command)
|
||||
|
||||
def remove_command(self, command: CommandBase):
|
||||
self._commands.remove(command)
|
||||
|
||||
def interpret(self, input_string: str):
|
||||
input_list = input_string.split(' ')
|
||||
command = input_list[0]
|
||||
if command is None or command == '':
|
||||
Console.error(f'Expected command')
|
||||
Console.error('Run \'cpl help\'')
|
||||
return
|
||||
|
||||
args = input_list[1:] if len(input_list) > 1 else []
|
||||
|
||||
cmd = next(
|
||||
(cmd for cmd in self._commands if type(cmd).__name__.lower() == command or command in cmd.aliases),
|
||||
None)
|
||||
if cmd is not None:
|
||||
cmd.run(args)
|
||||
else:
|
||||
Console.error(f'Unexpected command {command}')
|
||||
Console.error('Run \'cpl help\'')
|
@@ -1,25 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.coding
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.coding'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,27 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.coding.model
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.coding.model'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .version import Version
|
||||
from .version_enum import VersionEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,46 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from sh_edraft.coding.model.version_enum import VersionEnum
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
|
||||
|
||||
class Version(ConfigurationModelBase):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
major: int = None,
|
||||
minor: int = None,
|
||||
micro: float = None
|
||||
):
|
||||
ConfigurationModelBase.__init__(self)
|
||||
|
||||
self._major: Optional[int] = major
|
||||
self._minor: Optional[int] = minor
|
||||
self._micro: Optional[int] = micro
|
||||
|
||||
@property
|
||||
def major(self) -> int:
|
||||
return self._major
|
||||
|
||||
@property
|
||||
def minor(self) -> int:
|
||||
return self._minor
|
||||
|
||||
@property
|
||||
def micro(self) -> float:
|
||||
return self._micro
|
||||
|
||||
def to_str(self) -> str:
|
||||
return f'{self._major}.{self._minor}.{self._micro}'
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
self._major = int(settings[VersionEnum.Major.value])
|
||||
self._minor = int(settings[VersionEnum.Minor.value])
|
||||
self._micro = int(settings[VersionEnum.Micro.value])
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
VersionEnum.Major.value: self._major,
|
||||
VersionEnum.Minor.value: self._minor,
|
||||
VersionEnum.Micro.value: self._micro
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class VersionEnum(Enum):
|
||||
|
||||
Major = 'Major'
|
||||
Minor = 'Minor'
|
||||
Micro = 'Micro'
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.configuration
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .configuration import Configuration
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,27 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.configuration.base
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.configuration.base'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .configuration_base import ConfigurationBase
|
||||
from .configuration_model_base import ConfigurationModelBase
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.configuration.model
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.configuration.model'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .configuration_variable_name import ConfigurationVariableName
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.console
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .console import Console
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,27 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.console.model
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.console.model'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .background_color import BackgroundColor
|
||||
from .foreground_color import ForegroundColor
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,25 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.database
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.database'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.database.connection
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.database.connection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .database_connection import DatabaseConnection
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.database.connection.base
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.database.connection.base'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .database_connection_base import DatabaseConnectionBase
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.database.context
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.database.context'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .database_context import DatabaseContext
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.database.context.base
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.database.context.base'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .database_context_base import DatabaseContextBase
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.database.model
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.database.model'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .database_settings import DatabaseSettings
|
||||
from .database_settings_name import DatabaseSettingsName
|
||||
from .dbmodel import DBModel
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
@@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_edraft.environment
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
:copyright: (c) 2020 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_edraft.environment'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 sh-edraft.de'
|
||||
__version__ = '2020.12.9'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .hosting_environment import HostingEnvironment
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=9)
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user