2021-03-29 08:56:18 +02:00
|
|
|
import pathlib
|
|
|
|
from datetime import datetime
|
2020-11-28 15:13:54 +01:00
|
|
|
from socket import gethostname
|
|
|
|
from typing import Optional
|
|
|
|
|
2021-03-23 21:39:29 +01:00
|
|
|
from cpl.environment.application_environment_abc import ApplicationEnvironmentABC
|
2021-03-12 16:06:30 +01:00
|
|
|
from cpl.environment.environment_name_enum import EnvironmentNameEnum
|
2020-11-28 15:13:54 +01:00
|
|
|
|
|
|
|
|
2021-03-14 16:20:29 +01:00
|
|
|
class ApplicationEnvironment(ApplicationEnvironmentABC):
|
2020-11-28 15:13:54 +01:00
|
|
|
|
2021-03-12 16:06:30 +01:00
|
|
|
def __init__(self, name: EnvironmentNameEnum = EnvironmentNameEnum.production, crp: str = './'):
|
2021-03-14 16:20:29 +01:00
|
|
|
"""
|
|
|
|
Represents environment of the application
|
|
|
|
:param name:
|
|
|
|
:param crp:
|
|
|
|
"""
|
|
|
|
ApplicationEnvironmentABC.__init__(self)
|
2020-11-28 15:13:54 +01:00
|
|
|
|
2021-03-12 16:06:30 +01:00
|
|
|
self._environment_name: Optional[EnvironmentNameEnum] = name
|
2020-11-28 15:13:54 +01:00
|
|
|
self._app_name: Optional[str] = None
|
|
|
|
self._customer: Optional[str] = None
|
|
|
|
self._content_root_path: Optional[str] = crp
|
|
|
|
|
2021-03-29 08:56:18 +02:00
|
|
|
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()
|
|
|
|
|
2020-11-28 15:13:54 +01:00
|
|
|
@property
|
2020-11-29 17:29:16 +01:00
|
|
|
def environment_name(self) -> str:
|
|
|
|
return str(self._environment_name.value)
|
2020-11-28 15:13:54 +01:00
|
|
|
|
|
|
|
@environment_name.setter
|
2020-11-29 17:29:16 +01:00
|
|
|
def environment_name(self, environment_name: str):
|
2021-03-12 20:37:31 +01:00
|
|
|
self._environment_name = EnvironmentNameEnum(environment_name)
|
2020-11-28 15:13:54 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def application_name(self) -> str:
|
|
|
|
return self._app_name if self._app_name is not None else ''
|
|
|
|
|
|
|
|
@application_name.setter
|
|
|
|
def application_name(self, application_name: str):
|
|
|
|
self._app_name = application_name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def customer(self) -> str:
|
|
|
|
return self._customer if self._customer is not None else ''
|
|
|
|
|
|
|
|
@customer.setter
|
|
|
|
def customer(self, customer: str):
|
|
|
|
self._customer = customer
|
|
|
|
|
|
|
|
@property
|
|
|
|
def content_root_path(self) -> str:
|
|
|
|
return self._content_root_path
|
|
|
|
|
|
|
|
@content_root_path.setter
|
|
|
|
def content_root_path(self, content_root_path: str):
|
|
|
|
self._content_root_path = content_root_path
|
|
|
|
|
|
|
|
@property
|
|
|
|
def host_name(self):
|
|
|
|
return gethostname()
|
2021-03-29 08:56:18 +02: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()
|
|
|
|
|
|
|
|
@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()
|