1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-06 11:22:58 +00:00

trans_r and trans_w are not list anymore

This commit is contained in:
deadc0de6
2019-06-11 12:34:31 +02:00
parent d6d5ea2ccf
commit e0bbef6fb2
4 changed files with 25 additions and 36 deletions

View File

@@ -102,15 +102,14 @@ class CfgAggregator:
# patch trans_w/trans_r in dotfiles
self._patch_keys_to_objs(self.dotfiles,
"trans_r", self._get_trans_r)
"trans_r", self._get_trans_r, islist=False)
self._patch_keys_to_objs(self.dotfiles,
"trans_w", self._get_trans_w)
"trans_w", self._get_trans_w, islist=False)
def _patch_keys_to_objs(self, containers, keys, get_by_key):
def _patch_keys_to_objs(self, containers, keys, get_by_key, islist=True):
"""
patch each object in "containers" containing
a list of keys in the attribute "keys" with
the returned object of the function "get_by_key"
map for each key in the attribute 'keys' in 'containers'
the returned object from the method 'get_by_key'
"""
if not containers:
return
@@ -121,13 +120,17 @@ class CfgAggregator:
okeys = getattr(c, keys)
if not okeys:
continue
if not islist:
okeys = [okeys]
for k in okeys:
o = get_by_key(k)
if not o:
err = 'bad {} key for \"{}\": {}'.format(keys, c.key, k)
err = 'bad {} key for \"{}\": {}'.format(keys, c, k)
self.log.err(err)
raise Exception(err)
objects.append(o)
if not islist:
objects = objects[0]
if self.debug:
self.log.dbg('patching {}.{} with {}'.format(c, keys, objects))
setattr(c, keys, objects)