76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
"""
|
|
Config
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2023 Project Peter Yefi peteryefi@gmail.com
|
|
"""
|
|
import distutils
|
|
import os
|
|
import platform
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
import hub.helpers.dictionaries
|
|
from hub.persistence.db_control import DBControl
|
|
from hub.persistence.repository import Repository
|
|
from hub.catalog_factories.energy_systems_catalog_factory import EnergySystemsCatalogFactory
|
|
from pymongo import MongoClient
|
|
|
|
|
|
class Config:
|
|
|
|
def __init__(self):
|
|
dotenv_path = "{}/.local/etc/hub_api/.env".format(os.path.expanduser('~'))
|
|
if platform.system() == 'Linux':
|
|
dotenv_path = Path(dotenv_path).resolve()
|
|
environment = 'PROD'
|
|
load_dotenv(dotenv_path=dotenv_path)
|
|
self._database_name = os.getenv(f'{environment}_DB_NAME')
|
|
self._database = DBControl(db_name=self._database_name, app_env=environment, dotenv_path=dotenv_path)
|
|
self._repository = Repository(db_name=self._database_name, app_env=environment, dotenv_path=dotenv_path)
|
|
self._energy_systems_catalog = EnergySystemsCatalogFactory('montreal_custom').catalog
|
|
self._dictionaries = {
|
|
'pluto': hub.helpers.dictionaries.Dictionaries().pluto_function_to_hub_function,
|
|
'htf': hub.helpers.dictionaries.Dictionaries().hft_function_to_hub_function,
|
|
'montreal': hub.helpers.dictionaries.Dictionaries().montreal_function_to_hub_function,
|
|
'alkis': hub.helpers.dictionaries.Dictionaries().alkis_function_to_hub_function,
|
|
'eilat': hub.helpers.dictionaries.Dictionaries().eilat_function_to_hub_function
|
|
}
|
|
# mongodb
|
|
_mongodb = os.getenv(f'{environment}_MONGO_DB')
|
|
_mongodb_database = os.getenv(f'{environment}_MONGO_DB_DATABASE')
|
|
self._mongodb_collection_prefix = os.getenv(f'{environment}_MONGO_DB_COLLECTION_PREFIX')
|
|
_client = MongoClient(_mongodb)
|
|
self._montreal_retrofit_db = _client[_mongodb_database]
|
|
|
|
|
|
@property
|
|
def database(self):
|
|
return self._database
|
|
|
|
@property
|
|
def repository(self):
|
|
return self._repository
|
|
|
|
@property
|
|
def energy_systems_catalog(self):
|
|
return self._energy_systems_catalog
|
|
|
|
@staticmethod
|
|
def max_file_size():
|
|
return 10 * 1024 * 1024 # 10 MB
|
|
|
|
@property
|
|
def insel(self):
|
|
return distutils.spawn.find_executable('insel')
|
|
|
|
@property
|
|
def sra(self):
|
|
return distutils.spawn.find_executable('sra')
|
|
|
|
@property
|
|
def montreal_retrofit_db(self):
|
|
return self._montreal_retrofit_db
|
|
|
|
@property
|
|
def mongodb_collection_prefix(self):
|
|
return self._mongodb_collection_prefix
|