Refactor most of remaining config.get() calls

This commit is contained in:
Florian Bruhin 2017-06-14 21:47:26 +02:00
parent 51474724e5
commit 7ddce62cd6
7 changed files with 13 additions and 19 deletions

View File

@ -1547,7 +1547,7 @@ class CommandDispatcher:
raise cmdexc.CommandError("Invalid help topic {}!".format(
topic))
try:
config.get(*parts)
config.instance.get(*parts)
except configexc.NoSectionError:
raise cmdexc.CommandError("Invalid section {}!".format(
parts[0]))

View File

@ -91,8 +91,7 @@ def immediate_download_path(prompt_download_directory=None):
storage->prompt-download-directory setting.
"""
if prompt_download_directory is None:
prompt_download_directory = config.get('storage',
'prompt-download-directory')
prompt_download_directory = config.val.downloads.location.prompt
if not prompt_download_directory:
return download_dir()
@ -104,7 +103,7 @@ def _path_suggestion(filename):
Args:
filename: The filename to use if included in the suggestion.
"""
suggestion = config.val.completion.downloads.location.suggestion
suggestion = config.val.downloads.location.suggestion
if suggestion == 'path':
# add trailing '/' if not present
return os.path.join(download_dir(), '')
@ -473,10 +472,10 @@ class AbstractDownloadItem(QObject):
position: The color type requested, can be 'fg' or 'bg'.
"""
assert position in ["fg", "bg"]
start = config.get('colors', 'downloads.{}.start'.format(position))
stop = config.get('colors', 'downloads.{}.stop'.format(position))
system = config.get('colors', 'downloads.{}.system'.format(position))
error = config.get('colors', 'downloads.{}.error'.format(position))
start = getattr(config.val.colors.downloads.start, position)
stop = getattr(config.val.colors.downloads.stop, position)
system = getattr(config.val.colors.downloads.system, position)
error = getattr(config.val.colors.downloads.error, position)
if self.error_msg is not None:
assert not self.successful
return error

View File

@ -80,10 +80,10 @@ def _find_prevnext(prev, elems):
# Then check for regular links/buttons.
elems = [e for e in elems if e.tag_name() != 'link']
option = 'prev-regexes' if prev else 'next-regexes'
option = 'prev_regexes' if prev else 'next_regexes'
if not elems:
return None
for regex in config.get('hints', option):
for regex in getattr(config.val.hints, option):
log.hints.vdebug("== Checking regex '{}'.".format(regex.pattern))
for e in elems:
text = str(e)

View File

@ -180,7 +180,7 @@ def feature_permission(url, option, msg, yes_action, no_action, abort_on):
Return:
The Question object if a question was asked, None otherwise.
"""
config_val = config.get(*option)
config_val = config.instance.get(*option)
if config_val == 'ask':
if url.isValid():
text = "Allow the website at <b>{}</b> to {}?".format(

View File

@ -58,11 +58,6 @@ val = None
instance = None
def get(*args, **kwargs):
"""Convenience method to call get(...) of the config instance."""
return instance.get(*args, **kwargs)
def _init_main_config(parent=None):
"""Initialize the main config.

View File

@ -291,14 +291,14 @@ class LimitLineParser(LineParser):
assert self._configfile is not None
if option != self._limit:
return
value = config.get(option)
value = config.instance.get(option)
if value == 0:
if os.path.exists(self._configfile):
os.remove(self._configfile)
def save(self):
"""Save the config file."""
limit = config.get(self._limit)
limit = config.instance.get(self._limit)
if limit == 0:
return
do_save = self._prepare_save()

View File

@ -81,7 +81,7 @@ class Saveable:
force: Force saving, no matter what.
"""
if (self._config_opt is not None and
(not config.get(self._config_opt)) and
(not config.instance.get(self._config_opt)) and
(not explicit) and (not force)):
if not silent:
log.save.debug("Not saving {name} because autosaving has been "