mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-18 13:14:37 +03:00
Use borg for Settings class
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import os
|
|||||||
import posixpath
|
import posixpath
|
||||||
import secrets
|
import secrets
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
from logging import Handler, getLogger
|
from logging import Handler, getLogger
|
||||||
from logging.handlers import QueueListener
|
from logging.handlers import QueueListener
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -321,13 +322,30 @@ class SettingsClass:
|
|||||||
"""
|
"""
|
||||||
Class to hold configuration and settings.
|
Class to hold configuration and settings.
|
||||||
Actual values are stored in 'settings.ini' file.
|
Actual values are stored in 'settings.ini' file.
|
||||||
It also holds a combinations database.
|
It also holds a `combinations` database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# this class is Borg
|
||||||
|
_shared_state: Dict[str, Any] = {
|
||||||
|
"config": None,
|
||||||
|
"configfile": None,
|
||||||
|
"loggingconf": None,
|
||||||
|
"_combinations": None,
|
||||||
|
"_lock": threading.Lock(),
|
||||||
|
}
|
||||||
|
|
||||||
|
def __new__(cls, *p, **k):
|
||||||
|
self = object.__new__(cls, *p, **k)
|
||||||
|
self.__dict__ = cls._shared_state
|
||||||
|
return self
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = MyConfigParser()
|
if self.config is None:
|
||||||
self.configfile = os.path.join(os.path.dirname(__file__), "settings.ini")
|
with self._lock:
|
||||||
self.loggingconf = os.path.join(os.path.dirname(__file__), "logging.ini")
|
if self.config is None:
|
||||||
|
self.config = MyConfigParser()
|
||||||
|
self.configfile = os.path.join(os.path.dirname(__file__), "settings.ini")
|
||||||
|
self.loggingconf = os.path.join(os.path.dirname(__file__), "logging.ini")
|
||||||
|
|
||||||
def load_settings(self, file: Optional[Union[str, TextIO]] = None) -> None:
|
def load_settings(self, file: Optional[Union[str, TextIO]] = None) -> None:
|
||||||
with open(
|
with open(
|
||||||
|
|||||||
Reference in New Issue
Block a user