Refactor most of remaining config.get() calls
This commit is contained in:
parent
51474724e5
commit
7ddce62cd6
@ -1547,7 +1547,7 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError("Invalid help topic {}!".format(
|
raise cmdexc.CommandError("Invalid help topic {}!".format(
|
||||||
topic))
|
topic))
|
||||||
try:
|
try:
|
||||||
config.get(*parts)
|
config.instance.get(*parts)
|
||||||
except configexc.NoSectionError:
|
except configexc.NoSectionError:
|
||||||
raise cmdexc.CommandError("Invalid section {}!".format(
|
raise cmdexc.CommandError("Invalid section {}!".format(
|
||||||
parts[0]))
|
parts[0]))
|
||||||
|
@ -91,8 +91,7 @@ def immediate_download_path(prompt_download_directory=None):
|
|||||||
storage->prompt-download-directory setting.
|
storage->prompt-download-directory setting.
|
||||||
"""
|
"""
|
||||||
if prompt_download_directory is None:
|
if prompt_download_directory is None:
|
||||||
prompt_download_directory = config.get('storage',
|
prompt_download_directory = config.val.downloads.location.prompt
|
||||||
'prompt-download-directory')
|
|
||||||
|
|
||||||
if not prompt_download_directory:
|
if not prompt_download_directory:
|
||||||
return download_dir()
|
return download_dir()
|
||||||
@ -104,7 +103,7 @@ def _path_suggestion(filename):
|
|||||||
Args:
|
Args:
|
||||||
filename: The filename to use if included in the suggestion.
|
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':
|
if suggestion == 'path':
|
||||||
# add trailing '/' if not present
|
# add trailing '/' if not present
|
||||||
return os.path.join(download_dir(), '')
|
return os.path.join(download_dir(), '')
|
||||||
@ -473,10 +472,10 @@ class AbstractDownloadItem(QObject):
|
|||||||
position: The color type requested, can be 'fg' or 'bg'.
|
position: The color type requested, can be 'fg' or 'bg'.
|
||||||
"""
|
"""
|
||||||
assert position in ["fg", "bg"]
|
assert position in ["fg", "bg"]
|
||||||
start = config.get('colors', 'downloads.{}.start'.format(position))
|
start = getattr(config.val.colors.downloads.start, position)
|
||||||
stop = config.get('colors', 'downloads.{}.stop'.format(position))
|
stop = getattr(config.val.colors.downloads.stop, position)
|
||||||
system = config.get('colors', 'downloads.{}.system'.format(position))
|
system = getattr(config.val.colors.downloads.system, position)
|
||||||
error = config.get('colors', 'downloads.{}.error'.format(position))
|
error = getattr(config.val.colors.downloads.error, position)
|
||||||
if self.error_msg is not None:
|
if self.error_msg is not None:
|
||||||
assert not self.successful
|
assert not self.successful
|
||||||
return error
|
return error
|
||||||
|
@ -80,10 +80,10 @@ def _find_prevnext(prev, elems):
|
|||||||
|
|
||||||
# Then check for regular links/buttons.
|
# Then check for regular links/buttons.
|
||||||
elems = [e for e in elems if e.tag_name() != 'link']
|
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:
|
if not elems:
|
||||||
return None
|
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))
|
log.hints.vdebug("== Checking regex '{}'.".format(regex.pattern))
|
||||||
for e in elems:
|
for e in elems:
|
||||||
text = str(e)
|
text = str(e)
|
||||||
|
@ -180,7 +180,7 @@ def feature_permission(url, option, msg, yes_action, no_action, abort_on):
|
|||||||
Return:
|
Return:
|
||||||
The Question object if a question was asked, None otherwise.
|
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 config_val == 'ask':
|
||||||
if url.isValid():
|
if url.isValid():
|
||||||
text = "Allow the website at <b>{}</b> to {}?".format(
|
text = "Allow the website at <b>{}</b> to {}?".format(
|
||||||
|
@ -58,11 +58,6 @@ val = None
|
|||||||
instance = 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):
|
def _init_main_config(parent=None):
|
||||||
"""Initialize the main config.
|
"""Initialize the main config.
|
||||||
|
|
||||||
|
@ -291,14 +291,14 @@ class LimitLineParser(LineParser):
|
|||||||
assert self._configfile is not None
|
assert self._configfile is not None
|
||||||
if option != self._limit:
|
if option != self._limit:
|
||||||
return
|
return
|
||||||
value = config.get(option)
|
value = config.instance.get(option)
|
||||||
if value == 0:
|
if value == 0:
|
||||||
if os.path.exists(self._configfile):
|
if os.path.exists(self._configfile):
|
||||||
os.remove(self._configfile)
|
os.remove(self._configfile)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Save the config file."""
|
"""Save the config file."""
|
||||||
limit = config.get(self._limit)
|
limit = config.instance.get(self._limit)
|
||||||
if limit == 0:
|
if limit == 0:
|
||||||
return
|
return
|
||||||
do_save = self._prepare_save()
|
do_save = self._prepare_save()
|
||||||
|
@ -81,7 +81,7 @@ class Saveable:
|
|||||||
force: Force saving, no matter what.
|
force: Force saving, no matter what.
|
||||||
"""
|
"""
|
||||||
if (self._config_opt is not None and
|
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)):
|
(not explicit) and (not force)):
|
||||||
if not silent:
|
if not silent:
|
||||||
log.save.debug("Not saving {name} because autosaving has been "
|
log.save.debug("Not saving {name} because autosaving has been "
|
||||||
|
Loading…
Reference in New Issue
Block a user