Also rename options
This commit is contained in:
parent
5f7759eaed
commit
c561931699
@ -211,26 +211,26 @@ class ConfigManager(QObject):
|
|||||||
e.option = k
|
e.option = k
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def has_option(self, sectname, option):
|
def has_option(self, sectname, optname):
|
||||||
"""Check if option exists in section.
|
"""Check if option exists in section.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
sectname: The section name.
|
sectname: The section name.
|
||||||
option: The option name
|
optname: The option name
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if the option and section exist, False otherwise.
|
True if the option and section exist, False otherwise.
|
||||||
"""
|
"""
|
||||||
if sectname not in self.sections:
|
if sectname not in self.sections:
|
||||||
return False
|
return False
|
||||||
return option in self.sections[sectname]
|
return optname in self.sections[sectname]
|
||||||
|
|
||||||
def remove_option(self, sectname, option):
|
def remove_option(self, sectname, optname):
|
||||||
"""Remove an option.
|
"""Remove an option.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
sectname: The section where to remove an option.
|
sectname: The section where to remove an option.
|
||||||
option: The option name to remove.
|
optname: The option name to remove.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if the option existed, False otherwise.
|
True if the option existed, False otherwise.
|
||||||
@ -239,51 +239,51 @@ class ConfigManager(QObject):
|
|||||||
sectdict = self.sections[sectname]
|
sectdict = self.sections[sectname]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoSectionError(sectname)
|
raise NoSectionError(sectname)
|
||||||
option = self.optionxform(option)
|
optname = self.optionxform(optname)
|
||||||
existed = option in sectdict
|
existed = optname in sectdict
|
||||||
if existed:
|
if existed:
|
||||||
del sectdict[option]
|
del sectdict[optname]
|
||||||
return existed
|
return existed
|
||||||
|
|
||||||
@cmdutils.register(name='get', instance='config',
|
@cmdutils.register(name='get', instance='config',
|
||||||
completion=['section', 'option'])
|
completion=['section', 'option'])
|
||||||
def get_wrapper(self, sectname, option):
|
def get_wrapper(self, sectname, optname):
|
||||||
"""Get the value from a section/option.
|
"""Get the value from a section/option.
|
||||||
|
|
||||||
Wrapper for the get-command to output the value in the status bar.
|
Wrapper for the get-command to output the value in the status bar.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
val = self.get(sectname, option, transformed=False)
|
val = self.get(sectname, optname, transformed=False)
|
||||||
except (NoOptionError, NoSectionError) as e:
|
except (NoOptionError, NoSectionError) as e:
|
||||||
message.error("get: {} - {}".format(e.__class__.__name__, e))
|
message.error("get: {} - {}".format(e.__class__.__name__, e))
|
||||||
else:
|
else:
|
||||||
message.info("{} {} = {}".format(sectname, option, val))
|
message.info("{} {} = {}".format(sectname, optname, val))
|
||||||
|
|
||||||
def get(self, sectname, option, raw=False, transformed=True):
|
def get(self, sectname, optname, raw=False, transformed=True):
|
||||||
"""Get the value from a section/option.
|
"""Get the value from a section/option.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
sectname: The section to get the option from.
|
sectname: The section to get the option from.
|
||||||
option: The option name
|
optname: The option name
|
||||||
raw: Whether to get the uninterpolated, untransformed value.
|
raw: Whether to get the uninterpolated, untransformed value.
|
||||||
transformed: Whether the value should be transformed.
|
transformed: Whether the value should be transformed.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
The value of the option.
|
The value of the option.
|
||||||
"""
|
"""
|
||||||
logging.debug("getting {} -> {}".format(sectname, option))
|
logging.debug("getting {} -> {}".format(sectname, optname))
|
||||||
try:
|
try:
|
||||||
sect = self.sections[sectname]
|
sect = self.sections[sectname]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoSectionError(sectname)
|
raise NoSectionError(sectname)
|
||||||
try:
|
try:
|
||||||
val = sect[option]
|
val = sect[optname]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoOptionError(option, sectname)
|
raise NoOptionError(optname, sectname)
|
||||||
if raw:
|
if raw:
|
||||||
return val.value
|
return val.value
|
||||||
mapping = {key: val.value for key, val in sect.values.items()}
|
mapping = {key: val.value for key, val in sect.values.items()}
|
||||||
newval = self._interpolation.before_get(self, sectname, option,
|
newval = self._interpolation.before_get(self, sectname, optname,
|
||||||
val.value, mapping)
|
val.value, mapping)
|
||||||
logging.debug("interpolated val: {}".format(newval))
|
logging.debug("interpolated val: {}".format(newval))
|
||||||
if transformed:
|
if transformed:
|
||||||
@ -292,36 +292,36 @@ class ConfigManager(QObject):
|
|||||||
|
|
||||||
@cmdutils.register(name='set', instance='config',
|
@cmdutils.register(name='set', instance='config',
|
||||||
completion=['section', 'option', 'value'])
|
completion=['section', 'option', 'value'])
|
||||||
def set_wrapper(self, sectname, option, value):
|
def set_wrapper(self, sectname, optname, value):
|
||||||
"""Set an option.
|
"""Set an option.
|
||||||
|
|
||||||
Wrapper for self.set() to output exceptions in the status bar.
|
Wrapper for self.set() to output exceptions in the status bar.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.set('conf', sectname, option, value)
|
self.set('conf', sectname, optname, value)
|
||||||
except (NoOptionError, NoSectionError, ValidationError,
|
except (NoOptionError, NoSectionError, ValidationError,
|
||||||
ValueError) as e:
|
ValueError) as e:
|
||||||
message.error("set: {} - {}".format(e.__class__.__name__, e))
|
message.error("set: {} - {}".format(e.__class__.__name__, e))
|
||||||
|
|
||||||
@cmdutils.register(name='set_temp', instance='config',
|
@cmdutils.register(name='set_temp', instance='config',
|
||||||
completion=['section', 'option', 'value'])
|
completion=['section', 'option', 'value'])
|
||||||
def set_temp_wrapper(self, sectname, option, value):
|
def set_temp_wrapper(self, sectname, optname, value):
|
||||||
"""Set a temporary option.
|
"""Set a temporary option.
|
||||||
|
|
||||||
Wrapper for self.set() to output exceptions in the status bar.
|
Wrapper for self.set() to output exceptions in the status bar.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.set('temp', sectname, option, value)
|
self.set('temp', sectname, optname, value)
|
||||||
except (NoOptionError, NoSectionError, ValidationError) as e:
|
except (NoOptionError, NoSectionError, ValidationError) as e:
|
||||||
message.error("set: {} - {}".format(e.__class__.__name__, e))
|
message.error("set: {} - {}".format(e.__class__.__name__, e))
|
||||||
|
|
||||||
def set(self, layer, sectname, option, value):
|
def set(self, layer, sectname, optname, value):
|
||||||
"""Set an option.
|
"""Set an option.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
layer: A layer name as string (conf/temp/default).
|
layer: A layer name as string (conf/temp/default).
|
||||||
sectname: The name of the section to change.
|
sectname: The name of the section to change.
|
||||||
option: The name of the option to change.
|
optname: The name of the option to change.
|
||||||
value: The new value.
|
value: The new value.
|
||||||
|
|
||||||
Raise:
|
Raise:
|
||||||
@ -332,22 +332,22 @@ class ConfigManager(QObject):
|
|||||||
changed: If the config was changed.
|
changed: If the config was changed.
|
||||||
style_changed: When style caches need to be invalidated.
|
style_changed: When style caches need to be invalidated.
|
||||||
"""
|
"""
|
||||||
value = self._interpolation.before_set(self, sectname, option, value)
|
value = self._interpolation.before_set(self, sectname, optname, value)
|
||||||
try:
|
try:
|
||||||
sect = self.sections[sectname]
|
sect = self.sections[sectname]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoSectionError(sectname)
|
raise NoSectionError(sectname)
|
||||||
mapping = {key: val.value for key, val in sect.values.items()}
|
mapping = {key: val.value for key, val in sect.values.items()}
|
||||||
interpolated = self._interpolation.before_get(self, sectname, option,
|
interpolated = self._interpolation.before_get(self, sectname, optname,
|
||||||
value, mapping)
|
value, mapping)
|
||||||
try:
|
try:
|
||||||
sect.setv(layer, option, value, interpolated)
|
sect.setv(layer, optname, value, interpolated)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise NoOptionError(option, sectname)
|
raise NoOptionError(optname, sectname)
|
||||||
else:
|
else:
|
||||||
if sectname in ['colors', 'fonts']:
|
if sectname in ['colors', 'fonts']:
|
||||||
self.style_changed.emit(sectname, option)
|
self.style_changed.emit(sectname, optname)
|
||||||
self.changed.emit(sectname, option)
|
self.changed.emit(sectname, optname)
|
||||||
|
|
||||||
@cmdutils.register(instance='config')
|
@cmdutils.register(instance='config')
|
||||||
def save(self):
|
def save(self):
|
||||||
@ -427,18 +427,18 @@ class SectionProxy(MutableMapping):
|
|||||||
"""Get the option keys from this section."""
|
"""Get the option keys from this section."""
|
||||||
return self._conf.sections[self._name].keys()
|
return self._conf.sections[self._name].keys()
|
||||||
|
|
||||||
def get(self, option, *, raw=False):
|
def get(self, optname, *, raw=False):
|
||||||
"""Get a value from this section.
|
"""Get a value from this section.
|
||||||
|
|
||||||
We deliberately don't support the default argument here, but have a raw
|
We deliberately don't support the default argument here, but have a raw
|
||||||
argument instead.
|
argument instead.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
option: The option name to get.
|
optname: The option name to get.
|
||||||
raw: Whether to get a raw value or not.
|
raw: Whether to get a raw value or not.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=arguments-differ
|
# pylint: disable=arguments-differ
|
||||||
return self._conf.get(self._name, option, raw=raw)
|
return self._conf.get(self._name, optname, raw=raw)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def conf(self):
|
def conf(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user