Handle --relaxed-config for keys.conf as well.
This commit is contained in:
parent
3164ee06eb
commit
6ca39dd851
@ -161,7 +161,9 @@ def _init_key_config(parent):
|
|||||||
parent: The parent to use for the KeyConfigParser.
|
parent: The parent to use for the KeyConfigParser.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
args = objreg.get('args')
|
||||||
key_config = keyconf.KeyConfigParser(standarddir.config(), 'keys.conf',
|
key_config = keyconf.KeyConfigParser(standarddir.config(), 'keys.conf',
|
||||||
|
args.relaxed_config,
|
||||||
parent=parent)
|
parent=parent)
|
||||||
except (keyconf.KeyConfigError, UnicodeDecodeError) as e:
|
except (keyconf.KeyConfigError, UnicodeDecodeError) as e:
|
||||||
log.init.exception(e)
|
log.init.exception(e)
|
||||||
|
@ -75,12 +75,13 @@ class KeyConfigParser(QObject):
|
|||||||
config_dirty = pyqtSignal()
|
config_dirty = pyqtSignal()
|
||||||
UNBOUND_COMMAND = '<unbound>'
|
UNBOUND_COMMAND = '<unbound>'
|
||||||
|
|
||||||
def __init__(self, configdir, fname, parent=None):
|
def __init__(self, configdir, fname, relaxed=False, parent=None):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
configdir: The directory to save the configs in.
|
configdir: The directory to save the configs in.
|
||||||
fname: The filename of the config.
|
fname: The filename of the config.
|
||||||
|
relaxed: If given, unknwon commands are ignored.
|
||||||
"""
|
"""
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.is_dirty = False
|
self.is_dirty = False
|
||||||
@ -95,7 +96,7 @@ class KeyConfigParser(QObject):
|
|||||||
if self._configfile is None or not os.path.exists(self._configfile):
|
if self._configfile is None or not os.path.exists(self._configfile):
|
||||||
self._load_default()
|
self._load_default()
|
||||||
else:
|
else:
|
||||||
self._read()
|
self._read(relaxed)
|
||||||
self._load_default(only_new=True)
|
self._load_default(only_new=True)
|
||||||
log.init.debug("Loaded bindings: {}".format(self.keybindings))
|
log.init.debug("Loaded bindings: {}".format(self.keybindings))
|
||||||
|
|
||||||
@ -267,8 +268,12 @@ class KeyConfigParser(QObject):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _read(self):
|
def _read(self, relaxed=False):
|
||||||
"""Read the config file from disk and parse it."""
|
"""Read the config file from disk and parse it.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
relaxed: Ignore unknown commands.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
with open(self._configfile, 'r', encoding='utf-8') as f:
|
with open(self._configfile, 'r', encoding='utf-8') as f:
|
||||||
for i, line in enumerate(f):
|
for i, line in enumerate(f):
|
||||||
@ -287,8 +292,11 @@ class KeyConfigParser(QObject):
|
|||||||
line = line.strip()
|
line = line.strip()
|
||||||
self._read_command(line)
|
self._read_command(line)
|
||||||
except KeyConfigError as e:
|
except KeyConfigError as e:
|
||||||
e.lineno = i
|
if relaxed:
|
||||||
raise
|
continue
|
||||||
|
else:
|
||||||
|
e.lineno = i
|
||||||
|
raise
|
||||||
except OSError:
|
except OSError:
|
||||||
log.keyboard.exception("Failed to read key bindings!")
|
log.keyboard.exception("Failed to read key bindings!")
|
||||||
for sectname in self.keybindings:
|
for sectname in self.keybindings:
|
||||||
|
Loading…
Reference in New Issue
Block a user