Rename config.config dict to sections
This commit is contained in:
parent
3728381643
commit
a15461b5da
@ -79,7 +79,7 @@ class Config(QObject):
|
|||||||
"""Configuration manager for qutebrowser.
|
"""Configuration manager for qutebrowser.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
config: The configuration data as an OrderedDict.
|
sections: The configuration data as an OrderedDict.
|
||||||
_configparser: A ReadConfigParser instance to load the config.
|
_configparser: A ReadConfigParser instance to load the config.
|
||||||
_wrapper_args: A dict with the default kwargs for the config wrappers.
|
_wrapper_args: A dict with the default kwargs for the config wrappers.
|
||||||
_configdir: The dictionary to read the config from and save it in.
|
_configdir: The dictionary to read the config from and save it in.
|
||||||
@ -99,7 +99,7 @@ class Config(QObject):
|
|||||||
|
|
||||||
def __init__(self, configdir, fname, parent=None):
|
def __init__(self, configdir, fname, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.config = configdata.data
|
self.sections = configdata.data
|
||||||
self._configparser = ReadConfigParser(configdir, fname)
|
self._configparser = ReadConfigParser(configdir, fname)
|
||||||
self._configfile = os.path.join(configdir, fname)
|
self._configfile = os.path.join(configdir, fname)
|
||||||
self._wrapper_args = {
|
self._wrapper_args = {
|
||||||
@ -111,7 +111,7 @@ class Config(QObject):
|
|||||||
self._configdir = configdir
|
self._configdir = configdir
|
||||||
self._interpolation = ExtendedInterpolation()
|
self._interpolation = ExtendedInterpolation()
|
||||||
self._proxies = {}
|
self._proxies = {}
|
||||||
for secname, section in self.config.items():
|
for secname, section in self.sections.items():
|
||||||
self._proxies[secname] = SectionProxy(self, secname)
|
self._proxies[secname] = SectionProxy(self, secname)
|
||||||
try:
|
try:
|
||||||
section.from_cp(self._configparser[secname])
|
section.from_cp(self._configparser[secname])
|
||||||
@ -125,7 +125,7 @@ class Config(QObject):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Get the whole config as a string."""
|
"""Get the whole config as a string."""
|
||||||
lines = configdata.FIRST_COMMENT.strip('\n').splitlines()
|
lines = configdata.FIRST_COMMENT.strip('\n').splitlines()
|
||||||
for secname, section in self.config.items():
|
for secname, section in self.sections.items():
|
||||||
lines.append('\n[{}]'.format(secname))
|
lines.append('\n[{}]'.format(secname))
|
||||||
lines += self._str_section_desc(secname)
|
lines += self._str_section_desc(secname)
|
||||||
lines += self._str_option_desc(secname, section)
|
lines += self._str_option_desc(secname, section)
|
||||||
@ -162,7 +162,7 @@ class Config(QObject):
|
|||||||
typestr = ' ({})'.format(option.typ.typestr)
|
typestr = ' ({})'.format(option.typ.typestr)
|
||||||
lines.append('# {}{}:'.format(optname, typestr))
|
lines.append('# {}{}:'.format(optname, typestr))
|
||||||
try:
|
try:
|
||||||
desc = self.config[secname].descriptions[optname]
|
desc = self.sections[secname].descriptions[optname]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
for descline in desc.splitlines():
|
for descline in desc.splitlines():
|
||||||
@ -199,9 +199,9 @@ class Config(QObject):
|
|||||||
Return:
|
Return:
|
||||||
True if the option and section exist, False otherwise.
|
True if the option and section exist, False otherwise.
|
||||||
"""
|
"""
|
||||||
if section not in self.config:
|
if section not in self.sections:
|
||||||
return False
|
return False
|
||||||
return option in self.config[section]
|
return option in self.sections[section]
|
||||||
|
|
||||||
def remove_option(self, section, option):
|
def remove_option(self, section, option):
|
||||||
"""Remove an option.
|
"""Remove an option.
|
||||||
@ -214,7 +214,7 @@ class Config(QObject):
|
|||||||
True if the option existed, False otherwise.
|
True if the option existed, False otherwise.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
sectdict = self.config[section]
|
sectdict = self.sections[section]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoSectionError(section)
|
raise NoSectionError(section)
|
||||||
option = self.optionxform(option)
|
option = self.optionxform(option)
|
||||||
@ -250,7 +250,7 @@ class Config(QObject):
|
|||||||
"""
|
"""
|
||||||
logging.debug("getting {} -> {}".format(section, option))
|
logging.debug("getting {} -> {}".format(section, option))
|
||||||
try:
|
try:
|
||||||
sect = self.config[section]
|
sect = self.sections[section]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoSectionError(section)
|
raise NoSectionError(section)
|
||||||
try:
|
try:
|
||||||
@ -316,7 +316,7 @@ class Config(QObject):
|
|||||||
value = self._interpolation.before_set(self, section, option,
|
value = self._interpolation.before_set(self, section, option,
|
||||||
value)
|
value)
|
||||||
try:
|
try:
|
||||||
sect = self.config[section]
|
sect = self.sections[section]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoSectionError(section)
|
raise NoSectionError(section)
|
||||||
try:
|
try:
|
||||||
@ -345,7 +345,7 @@ class Config(QObject):
|
|||||||
"""
|
"""
|
||||||
# FIXME adopt this for layering
|
# FIXME adopt this for layering
|
||||||
lines = []
|
lines = []
|
||||||
for secname, section in self.config.items():
|
for secname, section in self.sections.items():
|
||||||
changed = section.dump_userconfig()
|
changed = section.dump_userconfig()
|
||||||
if changed:
|
if changed:
|
||||||
lines.append('[{}]'.format(secname))
|
lines.append('[{}]'.format(secname))
|
||||||
@ -405,7 +405,7 @@ class SectionProxy(MutableMapping):
|
|||||||
|
|
||||||
def _options(self):
|
def _options(self):
|
||||||
"""Get the option keys from this section."""
|
"""Get the option keys from this section."""
|
||||||
return self._conf.config[self._name].keys()
|
return self._conf.sections[self._name].keys()
|
||||||
|
|
||||||
def get(self, option, *, raw=False):
|
def get(self, option, *, raw=False):
|
||||||
"""Get a value from this section.
|
"""Get a value from this section.
|
||||||
|
Loading…
Reference in New Issue
Block a user