api_v1.4/hub_api/config.py

65 lines
2.0 KiB
Python
Raw Normal View History

"""
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
import hub.helpers.dictionaries
2023-07-20 20:15:24 -04:00
from hub.persistence.db_control import DBControl
2023-07-28 08:26:02 -04:00
from hub.persistence.repository import Repository
from hub.catalog_factories.energy_systems_catalog_factory import EnergySystemsCatalogFactory
class Config:
def __init__(self):
2023-08-03 09:53:26 -04:00
dotenv_path = "{}/.local/etc/hub_api/.env".format(os.path.expanduser('~'))
if platform.system() == 'Linux':
2023-08-03 09:53:26 -04:00
dotenv_path = Path(dotenv_path).resolve()
environment = 'PROD'
2023-11-28 01:42:03 -05:00
database_name = 'montreal_retrofit'
2024-04-25 01:19:21 -04:00
self._max_file_size = 10 * 1024 * 1024 # 10 MB
2023-07-20 20:15:24 -04:00
self._database = DBControl(db_name=database_name, app_env=environment, dotenv_path=dotenv_path)
2023-07-28 08:26:02 -04:00
self._repository = Repository(db_name=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
}
2023-07-20 20:15:24 -04:00
@property
def database(self):
return self._database
2023-07-28 08:26:02 -04:00
@property
def repository(self):
return self._repository
@property
def energy_systems_catalog(self):
return self._energy_systems_catalog
2024-04-25 01:19:21 -04:00
@property
def max_file_size(self):
return self._max_file_size
def function_dictionary(self, dictionary):
return self._dictionaries[dictionary]
@property
def insel(self):
return distutils.spawn.find_executable('insel')
@property
def sra(self):
return distutils.spawn.find_executable('sra')