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
command_history = lineparser.LimitLineParser(
standarddir.data(), 'cmd-history',
limit=('completion', 'cmd-history-max-items'),
limit='completion.cmd_history_max_items',
parent=objreg.get('config'))
objreg.register('command-history', command_history)
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.
Attributes:
_limit: The config section/option used to limit the maximum number of
lines.
_limit: The config option used to limit the maximum number of lines.
"""
def __init__(self, configdir, fname, *, limit, binary=False, parent=None):
@ -273,7 +272,7 @@ class LimitLineParser(LineParser):
Args:
configdir: Directory to read the config from, or None.
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.
"""
super().__init__(configdir, fname, binary=binary, parent=parent)
@ -286,20 +285,20 @@ class LimitLineParser(LineParser):
configdir=self._configdir, fname=self._fname,
limit=self._limit, binary=self._binary)
@pyqtSlot(str, str)
def cleanup_file(self, section, option):
@pyqtSlot(str)
def cleanup_file(self, option):
"""Delete the file if the limit was changed to 0."""
assert self._configfile is not None
if (section, option) != self._limit:
if option != self._limit:
return
value = config.get(section, option)
value = config.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.get(self._limit)
if limit == 0:
return
do_save = self._prepare_save()