Split ConfigManager.read from constructor.
This commit is contained in:
parent
b3b2fb51fc
commit
10dd1b50b9
@ -140,9 +140,10 @@ def _init_main_config(parent=None):
|
|||||||
parent: The parent to pass to ConfigManager.
|
parent: The parent to pass to ConfigManager.
|
||||||
"""
|
"""
|
||||||
args = objreg.get('args')
|
args = objreg.get('args')
|
||||||
|
config_obj = ConfigManager(parent=parent)
|
||||||
try:
|
try:
|
||||||
config_obj = ConfigManager(standarddir.config(), 'qutebrowser.conf',
|
config_obj.read(standarddir.config(), 'qutebrowser.conf',
|
||||||
args.relaxed_config, parent=parent)
|
relaxed=args.relaxed_config)
|
||||||
except (configexc.Error, configparser.Error, UnicodeDecodeError) as e:
|
except (configexc.Error, configparser.Error, UnicodeDecodeError) as e:
|
||||||
log.init.exception(e)
|
log.init.exception(e)
|
||||||
errstr = "Error while reading config:"
|
errstr = "Error while reading config:"
|
||||||
@ -362,24 +363,16 @@ class ConfigManager(QObject):
|
|||||||
changed = pyqtSignal(str, str)
|
changed = pyqtSignal(str, str)
|
||||||
style_changed = pyqtSignal(str, str)
|
style_changed = pyqtSignal(str, str)
|
||||||
|
|
||||||
def __init__(self, configdir, fname, relaxed=False, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
|
self._configdir = None
|
||||||
|
self._fname = None
|
||||||
self.sections = configdata.data()
|
self.sections = configdata.data()
|
||||||
self._interpolation = configparser.ExtendedInterpolation()
|
self._interpolation = configparser.ExtendedInterpolation()
|
||||||
self._proxies = {}
|
self._proxies = {}
|
||||||
for sectname in self.sections:
|
for sectname in self.sections:
|
||||||
self._proxies[sectname] = SectionProxy(self, sectname)
|
self._proxies[sectname] = SectionProxy(self, sectname)
|
||||||
self._fname = fname
|
|
||||||
if configdir is None:
|
|
||||||
self._configdir = None
|
|
||||||
self._initialized = True
|
|
||||||
else:
|
|
||||||
self._configdir = configdir
|
|
||||||
parser = ini.ReadConfigParser(configdir, fname)
|
|
||||||
self._from_cp(parser, relaxed)
|
|
||||||
self._initialized = True
|
|
||||||
self._validate_all()
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
"""Get a section from the config."""
|
"""Get a section from the config."""
|
||||||
@ -571,6 +564,19 @@ class ConfigManager(QObject):
|
|||||||
option.value()):
|
option.value()):
|
||||||
self._changed(sectname, optname)
|
self._changed(sectname, optname)
|
||||||
|
|
||||||
|
def read(self, configdir, fname, relaxed=False):
|
||||||
|
"""Read the config from the given directory/file."""
|
||||||
|
self._fname = fname
|
||||||
|
if configdir is None:
|
||||||
|
self._configdir = None
|
||||||
|
self._initialized = True
|
||||||
|
else:
|
||||||
|
self._configdir = configdir
|
||||||
|
parser = ini.ReadConfigParser(configdir, fname)
|
||||||
|
self._from_cp(parser, relaxed)
|
||||||
|
self._initialized = True
|
||||||
|
self._validate_all()
|
||||||
|
|
||||||
def items(self, sectname, raw=True):
|
def items(self, sectname, raw=True):
|
||||||
"""Get a list of (optname, value) tuples for a section.
|
"""Get a list of (optname, value) tuples for a section.
|
||||||
|
|
||||||
|
@ -47,7 +47,8 @@ class TestConfigParser:
|
|||||||
cp = configparser.ConfigParser(interpolation=None,
|
cp = configparser.ConfigParser(interpolation=None,
|
||||||
comment_prefixes='#')
|
comment_prefixes='#')
|
||||||
cp.optionxform = lambda opt: opt # be case-insensitive
|
cp.optionxform = lambda opt: opt # be case-insensitive
|
||||||
cfg = config.ConfigManager(None, None)
|
cfg = config.ConfigManager()
|
||||||
|
cfg.read(None, None)
|
||||||
return self.Objects(cp=cp, cfg=cfg)
|
return self.Objects(cp=cp, cfg=cfg)
|
||||||
|
|
||||||
def test_simple(self, objects):
|
def test_simple(self, objects):
|
||||||
@ -272,7 +273,7 @@ class TestDefaultConfig:
|
|||||||
@pytest.mark.usefixtures('qapp')
|
@pytest.mark.usefixtures('qapp')
|
||||||
def test_default_config(self):
|
def test_default_config(self):
|
||||||
"""Test validating of the default config."""
|
"""Test validating of the default config."""
|
||||||
conf = config.ConfigManager(None, None)
|
conf = config.ConfigManager()
|
||||||
conf._validate_all()
|
conf._validate_all()
|
||||||
|
|
||||||
def test_default_key_config(self):
|
def test_default_key_config(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user