WIP: Temporary commit for branch move
This commit is contained in:
@@ -1,35 +1,46 @@
|
||||
import configparser
|
||||
import os
|
||||
import sys
|
||||
|
||||
from database.db import BotDB
|
||||
|
||||
current_dir = os.getcwd()
|
||||
|
||||
|
||||
class BaseDependencyFactory:
|
||||
def __init__(self):
|
||||
# Загрузка настроек из settings.ini
|
||||
config_path = os.path.join(sys.path[0], 'settings.ini')
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read(config_path)
|
||||
self.settings = {}
|
||||
self.database = BotDB(current_dir, 'database/tg-bot-database')
|
||||
|
||||
for section in self.config.sections():
|
||||
self.settings[section] = {}
|
||||
for key in self.config[section]:
|
||||
# Преобразование значений в соответствующий тип
|
||||
if key == 'PREVIEW_LINK':
|
||||
self.settings[section][key] = self.config.getboolean(section, key)
|
||||
elif key == 'LOGS' or key == 'TEST':
|
||||
self.settings[section][key] = self.config.getboolean(section, key)
|
||||
else:
|
||||
self.settings[section][key] = self.config.get(section, key)
|
||||
|
||||
def get_settings(self):
|
||||
return self.settings
|
||||
|
||||
def get_db(self) -> BotDB:
|
||||
"""Возвращает подключение к базе данных."""
|
||||
return self.database
|
||||
import configparser
|
||||
import os
|
||||
import sys
|
||||
|
||||
from database.db import BotDB
|
||||
|
||||
current_dir = os.getcwd()
|
||||
|
||||
|
||||
class BaseDependencyFactory:
|
||||
def __init__(self):
|
||||
# Загрузка настроек из settings.ini
|
||||
config_path = os.path.join(sys.path[0], 'settings.ini')
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read(config_path)
|
||||
self.settings = {}
|
||||
self.database = BotDB(current_dir, 'tg-bot-database.db')
|
||||
|
||||
for section in self.config.sections():
|
||||
self.settings[section] = {}
|
||||
for key in self.config[section]:
|
||||
# Преобразование значений в соответствующий тип
|
||||
if key == 'PREVIEW_LINK':
|
||||
self.settings[section][key] = self.config.getboolean(section, key)
|
||||
elif key == 'LOGS' or key == 'TEST':
|
||||
self.settings[section][key] = self.config.getboolean(section, key)
|
||||
else:
|
||||
self.settings[section][key] = self.config.get(section, key)
|
||||
|
||||
def get_settings(self):
|
||||
return self.settings
|
||||
|
||||
def get_db(self) -> BotDB:
|
||||
"""Возвращает подключение к базе данных."""
|
||||
return self.database
|
||||
|
||||
|
||||
# Создаем единый экземпляр для всего приложения
|
||||
_global_instance = None
|
||||
|
||||
def get_global_instance():
|
||||
"""Возвращает глобальный экземпляр BaseDependencyFactory."""
|
||||
global _global_instance
|
||||
if _global_instance is None:
|
||||
_global_instance = BaseDependencyFactory()
|
||||
return _global_instance
|
||||
|
||||
Reference in New Issue
Block a user