Fix LimitLineParser

This commit is contained in:
Florian Bruhin 2017-06-13 16:07:12 +02:00
parent 1022b7ea32
commit c25022f549
2 changed files with 8 additions and 9 deletions

View File

@ -158,7 +158,7 @@ def _init_misc():
from qutebrowser.misc import lineparser from qutebrowser.misc import lineparser
command_history = lineparser.LimitLineParser( command_history = lineparser.LimitLineParser(
standarddir.data(), 'cmd-history', standarddir.data(), 'cmd-history',
limit=('completion', 'cmd-history-max-items'), limit='completion.cmd_history_max_items',
parent=objreg.get('config')) parent=objreg.get('config'))
objreg.register('command-history', command_history) objreg.register('command-history', command_history)
save_manager.add_saveable('command-history', command_history.save, save_manager.add_saveable('command-history', command_history.save,

View File

@ -263,8 +263,7 @@ class LimitLineParser(LineParser):
"""A LineParser with a limited count of lines. """A LineParser with a limited count of lines.
Attributes: Attributes:
_limit: The config section/option used to limit the maximum number of _limit: The config option used to limit the maximum number of lines.
lines.
""" """
def __init__(self, configdir, fname, *, limit, binary=False, parent=None): def __init__(self, configdir, fname, *, limit, binary=False, parent=None):
@ -273,7 +272,7 @@ class LimitLineParser(LineParser):
Args: Args:
configdir: Directory to read the config from, or None. configdir: Directory to read the config from, or None.
fname: Filename of the config file. fname: Filename of the config file.
limit: Config tuple (section, option) which contains a limit. limit: Config option which contains a limit.
binary: Whether to open the file in binary mode. binary: Whether to open the file in binary mode.
""" """
super().__init__(configdir, fname, binary=binary, parent=parent) super().__init__(configdir, fname, binary=binary, parent=parent)
@ -286,20 +285,20 @@ class LimitLineParser(LineParser):
configdir=self._configdir, fname=self._fname, configdir=self._configdir, fname=self._fname,
limit=self._limit, binary=self._binary) limit=self._limit, binary=self._binary)
@pyqtSlot(str, str) @pyqtSlot(str)
def cleanup_file(self, section, option): def cleanup_file(self, option):
"""Delete the file if the limit was changed to 0.""" """Delete the file if the limit was changed to 0."""
assert self._configfile is not None assert self._configfile is not None
if (section, option) != self._limit: if option != self._limit:
return return
value = config.get(section, option) value = config.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.get(self._limit)
if limit == 0: if limit == 0:
return return
do_save = self._prepare_save() do_save = self._prepare_save()