2021-03-04 07:09:08 +01:00
|
|
|
import pathlib
|
2020-11-26 18:58:08 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
2021-03-03 10:47:52 +01:00
|
|
|
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
|
|
|
from cpl.configuration.configuration_abc import ConfigurationABC
|
2020-11-26 18:58:08 +01:00
|
|
|
|
|
|
|
|
2021-03-03 10:47:52 +01:00
|
|
|
class ApplicationRuntime(ApplicationRuntimeABC):
|
2020-11-26 18:58:08 +01:00
|
|
|
|
2021-03-03 10:47:52 +01:00
|
|
|
def __init__(self, config: ConfigurationABC):
|
2021-03-14 16:57:20 +01:00
|
|
|
"""
|
|
|
|
Representation of the application runtime
|
|
|
|
:param config:
|
|
|
|
"""
|
2021-03-03 10:47:52 +01:00
|
|
|
ApplicationRuntimeABC.__init__(self)
|
2020-11-26 18:58:08 +01:00
|
|
|
|
2020-11-26 19:17:05 +01:00
|
|
|
self._app_configuration = config
|
2020-11-26 18:58:08 +01:00
|
|
|
self._start_time: datetime = datetime.now()
|
|
|
|
self._end_time: datetime = datetime.now()
|
2021-03-04 07:09:08 +01:00
|
|
|
self._working_directory = pathlib.Path().absolute()
|
|
|
|
self._runtime_directory = pathlib.Path(__file__).parent.absolute()
|
2020-11-26 19:17:05 +01:00
|
|
|
|
2020-11-26 18:58:08 +01:00
|
|
|
@property
|
2021-03-03 10:47:52 +01:00
|
|
|
def configuration(self) -> ConfigurationABC:
|
2020-11-26 19:17:05 +01:00
|
|
|
return self._app_configuration
|
2020-11-27 18:18:07 +01:00
|
|
|
|
2020-11-26 18:58:08 +01:00
|
|
|
@property
|
|
|
|
def start_time(self) -> datetime:
|
|
|
|
return self._start_time
|
|
|
|
|
|
|
|
@property
|
|
|
|
def end_time(self) -> datetime:
|
|
|
|
return self._end_time
|
|
|
|
|
|
|
|
@end_time.setter
|
|
|
|
def end_time(self, end_time: datetime):
|
|
|
|
self._end_time = end_time
|
|
|
|
|
|
|
|
@property
|
|
|
|
def date_time_now(self) -> datetime:
|
|
|
|
return datetime.now()
|
2021-03-04 07:09:08 +01:00
|
|
|
|
|
|
|
@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()
|