mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-09 17:20:17 +00:00
Add the tomli library and create the config_manager.py to manage the configuration file and also add the dependency injection on the ui.py via the Application class
This commit is contained in:
parent
0adb230dd7
commit
3843be6e13
@@ -1,3 +1,4 @@
|
||||
from .directory_manager import DirectoryManager
|
||||
from .config_manager import ConfigManager
|
||||
|
||||
__all__ = ['DirectoryManager']
|
||||
__all__ = ['DirectoryManager', 'ConfigManager']
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
from threading import Lock
|
||||
|
||||
import tomli
|
||||
from pilgrim.utils import DirectoryManager
|
||||
|
||||
class SingletonMeta(type):
|
||||
_instances = {}
|
||||
_lock: Lock = Lock()
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
with cls._lock:
|
||||
if cls not in cls._instances:
|
||||
instance = super().__call__(*args, **kwargs)
|
||||
cls._instances[cls] = instance
|
||||
return cls._instances[cls]
|
||||
|
||||
class ConfigManager(metaclass=SingletonMeta):
|
||||
def __init__(self):
|
||||
self.database_url = None
|
||||
self.database_type = None
|
||||
self.auto_open_diary = None
|
||||
self.auto_open_new_diary = None
|
||||
@staticmethod
|
||||
def read_config():
|
||||
try:
|
||||
with open(f"{DirectoryManager.get_config_directory()}/config.toml", "rb") as f:
|
||||
data = tomli.load(f)
|
||||
print(data)
|
||||
except FileNotFoundError:
|
||||
print("Error: config.toml not found.")
|
||||
except tomli.TOMLDecodeError as e:
|
||||
print(f"Error decoding TOML: {e}")
|
||||
|
||||
def set_database_url(self):
|
||||
pass
|
||||
Reference in New Issue
Block a user