Ejemplo n.º 1
0
class AppConfigs(ABC):
    __root_dir = pathlib.Path(sys.argv[0]).parent.absolute()
    __log_file = "{}/../log/qt_calculator.log".format(__root_dir)
    __log = log_init(__log_file)
    __app_properties = Properties(load_dir="{}/resources".format(__root_dir))
    __log.info('Successfully read {} properties'.format(
        __app_properties.size()))

    @staticmethod
    def get(property_name: str) -> str:
        return AppConfigs.__app_properties.get(
            property_name) if AppConfigs.__app_properties else None

    @staticmethod
    def get_int(property_name: str) -> int:
        return AppConfigs.__app_properties.get_int(
            property_name) if AppConfigs.__app_properties else None

    @staticmethod
    def get_float(property_name: str) -> float:
        return AppConfigs.__app_properties.get_float(
            property_name) if AppConfigs.__app_properties else None

    @staticmethod
    def get_bool(property_name: str) -> bool:
        return AppConfigs.__app_properties.get_bool(
            property_name) if AppConfigs.__app_properties else None

    @staticmethod
    def root_dir() -> str:
        return AppConfigs.__root_dir

    @staticmethod
    def log_file() -> str:
        return AppConfigs.__log_file
Ejemplo n.º 2
0
class AppConfigs(ABC):
    __root_dir = pathlib.Path(sys.argv[0]).parent.absolute()
    __log_file = "{}/../log/car-rental.log".format(__root_dir)
    __log = log_init(__log_file)
    __app_properties = Properties(load_dir="{}/resources".format(__root_dir))
    __log.info('Successfully read {} properties'.format(
        __app_properties.size()))
    __repository_type = RepositoryType[__app_properties.get(
        'persistence.repository.type').upper()]
    __database_type = DatabaseType[__app_properties.get(
        'persistence.database.type').upper()]
    __log.info(
        'App configs loaded repository_type={} database_type={} root_dir={}'.
        format(__repository_type, __database_type, __root_dir))

    @staticmethod
    def get(property_name: str) -> str:
        return AppConfigs.__app_properties.get(
            property_name) if AppConfigs.__app_properties else None

    @staticmethod
    def get_int(property_name: str) -> int:
        return AppConfigs.__app_properties.get_int(
            property_name) if AppConfigs.__app_properties else None

    @staticmethod
    def get_float(property_name: str) -> float:
        return AppConfigs.__app_properties.get_float(
            property_name) if AppConfigs.__app_properties else None

    @staticmethod
    def get_bool(property_name: str) -> bool:
        return AppConfigs.__app_properties.get_bool(
            property_name) if AppConfigs.__app_properties else None

    @staticmethod
    def root_dir() -> str:
        return AppConfigs.__root_dir

    @staticmethod
    def log_file() -> str:
        return AppConfigs.__log_file

    @staticmethod
    def repository_type() -> RepositoryType:
        return AppConfigs.__repository_type

    @staticmethod
    def database_type() -> DatabaseType:
        return AppConfigs.__database_type
 def __init__(self,
              source_root: str = None,
              resource_dir: str = None,
              log_dir: str = None,
              log_file: str = 'application.log'):
     self._source_root = source_root or os.environ.get('SOURCE_ROOT', os.path.abspath(os.curdir))
     assert os.path.exists(self._source_root), "Unable to find the source directory: {}".format(self._source_root)
     self._log_dir = log_dir if log_dir else '{}/../log'.format(os.environ.get('LOG_DIR', self._source_root))
     assert os.path.exists(self._log_dir), "Unable to find the log directory: {}".format(self._log_dir)
     self._log_file = "{}/{}".format(self._log_dir, log_file)
     self._logger = log_init(self._log_file)
     assert self._logger, "Unable to create the logger: {}".format(str(self._logger))
     self._resource_dir = resource_dir \
         if resource_dir else os.environ.get('RESOURCE_DIR', "{}/resources".format(self._source_root))
     self._app_properties = Properties(load_dir=self._resource_dir)
Ejemplo n.º 4
0
from abc import ABC
from typing import Type

from core.config.app_configs import AppConfigs
from src.core.enum.database_type import DatabaseType
from src.core.enum.model import Model
from src.core.enum.repository_type import RepositoryType
from src.core.service.car_service import CarService
from src.core.service.customer_service import CustomerService
from src.core.service.employee_service import EmployeeService
from src.core.service.rental_service import RentalService
from src.core.service.service import Service
from src.core.tools.commons import log_init

LOG = log_init(AppConfigs.log_file())


class ServiceFacade(ABC):
    __cache = {}
    __services = {
        Model.CAR.name: CarService,
        Model.CUSTOMER.name: CustomerService,
        Model.EMPLOYEE.name: EmployeeService,
        Model.RENTAL.name: RentalService,
    }

    @staticmethod
    def create_or_get(service_class: Type, repository_type: RepositoryType, database_type: DatabaseType):
        cache_key = service_class.__name__
        if cache_key in ServiceFacade.__cache:
            LOG.info('Retrieving service {}'.format(cache_key))
Ejemplo n.º 5
0
 def __init__(self, window: QWidget, parent=None):
     super().__init__()
     self.window = window
     self.parent = parent
     self.log = log_init(AppConfigs.log_file())
     self.qt = QtFinder(self.window)
Ejemplo n.º 6
0
 def __init__(self, filename: str):
     super().__init__(filename)
     self.log = log_init(AppConfigs.log_file())
     self.db_filename = filename
     self.localDb = self.__create_or_get()