mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 08:04:16 +00:00
Using try-catch KeyError: instead of if in config parser
This commit is contained in:
@@ -237,9 +237,11 @@ class Cfg:
|
|||||||
self.lnk_settings[self.key_workdir] = self._abs_path(self.curworkdir)
|
self.lnk_settings[self.key_workdir] = self._abs_path(self.curworkdir)
|
||||||
|
|
||||||
# load external variables/dynvariables
|
# load external variables/dynvariables
|
||||||
if self.key_import_vars in self.lnk_settings:
|
try:
|
||||||
paths = self.lnk_settings[self.key_import_vars]
|
paths = self.lnk_settings[self.key_import_vars] or []
|
||||||
self._load_ext_variables(paths, profile=profile)
|
self._load_ext_variables(paths, profile=profile)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
# parse external actions
|
# parse external actions
|
||||||
try:
|
try:
|
||||||
@@ -248,28 +250,38 @@ class Cfg:
|
|||||||
if self.debug:
|
if self.debug:
|
||||||
self.log.dbg('loading actions from {}'.format(path))
|
self.log.dbg('loading actions from {}'.format(path))
|
||||||
content = self._load_yaml(path)
|
content = self._load_yaml(path)
|
||||||
if self.key_actions in content and \
|
# If external actions are None, replaces them with empty dict
|
||||||
content[self.key_actions] is not None:
|
try:
|
||||||
self._load_actions(content[self.key_actions])
|
external_actions = content[self.key_actions] or {}
|
||||||
|
self._load_actions(external_actions)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# parse local actions
|
# parse local actions
|
||||||
if self.key_actions in self.content and \
|
# If local actions are None, replaces them with empty dict
|
||||||
self.content[self.key_actions] is not None:
|
try:
|
||||||
self._load_actions(self.content[self.key_actions])
|
local_actions = self.content[self.key_actions] or {}
|
||||||
|
self._load_actions(local_actions)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
# parse read transformations
|
# parse read transformations
|
||||||
if self.key_trans_r in self.content and \
|
# If read transformations are None, replaces them with empty dict
|
||||||
self.content[self.key_trans_r] is not None:
|
try:
|
||||||
for k, v in self.content[self.key_trans_r].items():
|
read_trans = self.content[self.key_trans_r] or {}
|
||||||
self.trans_r[k] = Transform(k, v)
|
self.trans_r = {k: Transform(k, v) for k, v in read_trans.items()}
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
# parse write transformations
|
# parse write transformations
|
||||||
if self.key_trans_w in self.content and \
|
# If write transformations are None, replaces them with empty dict
|
||||||
self.content[self.key_trans_w] is not None:
|
try:
|
||||||
for k, v in self.content[self.key_trans_w].items():
|
read_trans = self.content[self.key_trans_w] or {}
|
||||||
self.trans_w[k] = Transform(k, v)
|
self.trans_w = {k: Transform(k, v) for k, v in read_trans.items()}
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
# parse the dotfiles and construct the dict of objects per dotfile key
|
# parse the dotfiles and construct the dict of objects per dotfile key
|
||||||
# ensures the dotfiles entry is a dict
|
# ensures the dotfiles entry is a dict
|
||||||
|
|||||||
Reference in New Issue
Block a user