Improved application
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import atexit
|
||||
from collections import Callable
|
||||
from datetime import datetime
|
||||
|
||||
from cpl.application.application_host_abc import ApplicationHostABC
|
||||
from cpl.application.application_runtime import ApplicationRuntime
|
||||
@@ -22,10 +21,6 @@ class ApplicationHost(ApplicationHostABC):
|
||||
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()
|
||||
|
||||
@property
|
||||
def configuration(self) -> ConfigurationABC:
|
||||
return self._config
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import pathlib
|
||||
from datetime import datetime
|
||||
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
@@ -12,6 +13,8 @@ class ApplicationRuntime(ApplicationRuntimeABC):
|
||||
self._app_configuration = config
|
||||
self._start_time: datetime = datetime.now()
|
||||
self._end_time: datetime = datetime.now()
|
||||
self._working_directory = pathlib.Path().absolute()
|
||||
self._runtime_directory = pathlib.Path(__file__).parent.absolute()
|
||||
|
||||
@property
|
||||
def configuration(self) -> ConfigurationABC:
|
||||
@@ -21,10 +24,6 @@ class ApplicationRuntime(ApplicationRuntimeABC):
|
||||
def start_time(self) -> datetime:
|
||||
return self._start_time
|
||||
|
||||
@start_time.setter
|
||||
def start_time(self, start_time: datetime):
|
||||
self._start_time = start_time
|
||||
|
||||
@property
|
||||
def end_time(self) -> datetime:
|
||||
return self._end_time
|
||||
@@ -36,3 +35,21 @@ class ApplicationRuntime(ApplicationRuntimeABC):
|
||||
@property
|
||||
def date_time_now(self) -> datetime:
|
||||
return datetime.now()
|
||||
|
||||
@property
|
||||
def working_directory(self) -> str:
|
||||
return self._working_directory
|
||||
|
||||
def set_working_directory(self, path: str = ''):
|
||||
if path != '':
|
||||
self._working_directory = path
|
||||
return
|
||||
|
||||
self._working_directory = pathlib.Path().absolute()
|
||||
|
||||
@property
|
||||
def runtime_directory(self) -> str:
|
||||
return self._runtime_directory
|
||||
|
||||
def set_runtime_directory(self, file: str):
|
||||
self._runtime_directory = pathlib.Path(file).parent.absolute()
|
||||
|
@@ -32,3 +32,14 @@ class ApplicationRuntimeABC(ABC):
|
||||
@property
|
||||
@abstractmethod
|
||||
def date_time_now(self) -> datetime: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def working_directory(self) -> str: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def runtime_directory(self) -> str: pass
|
||||
|
||||
@abstractmethod
|
||||
def set_runtime_directory(self, runtime_directory: str): pass
|
||||
|
@@ -22,18 +22,20 @@ class Startup(StartupABC):
|
||||
|
||||
def create_application_host(self) -> ApplicationHostABC:
|
||||
self._app_host = ApplicationHost()
|
||||
|
||||
self._app_host.application_runtime.set_runtime_directory(__file__)
|
||||
self._app_host.console_argument_error_function(Error.error)
|
||||
|
||||
self._configuration = self._app_host.configuration
|
||||
self._services = self._app_host.services
|
||||
|
||||
self._app_host.console_argument_error_function(Error.error)
|
||||
|
||||
return self._app_host
|
||||
|
||||
def create_configuration(self) -> ConfigurationABC:
|
||||
self._configuration.add_environment_variables('PYTHON_')
|
||||
self._configuration.add_environment_variables('CPL_')
|
||||
self._configuration.add_console_argument('', 'help', ['h'], '')
|
||||
self._configuration.add_console_argument('', 'version', ['v'], '')
|
||||
self._configuration.add_console_argument('', 'help', ['-h', '-H'], '')
|
||||
self._configuration.add_console_argument('', 'version', ['-v', '-V'], '')
|
||||
self._configuration.add_console_arguments()
|
||||
|
||||
return self._configuration
|
||||
|
Reference in New Issue
Block a user