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

allow to have dynamic dotfile actions for #120

This commit is contained in:
deadc0de6
2019-04-27 14:34:34 +02:00
parent 018b2361aa
commit 222925dd29

View File

@@ -306,7 +306,12 @@ class Cfg:
# parse actions
itsactions = v[self.key_dotfiles_actions] if \
self.key_dotfiles_actions in v else []
actions = self._parse_actions(itsactions)
actions = self._parse_actions(itsactions, profile=profile)
if self.debug:
self.log.dbg('action for {}'.format(k))
for t in [self.key_actions_pre, self.key_actions_post]:
for action in actions[t]:
self.log.dbg('- {}: {}'.format(t, action))
# parse read transformation
itstrans_r = v[self.key_dotfiles_trans_r] if \
@@ -540,19 +545,25 @@ class Cfg:
dotfiles.extend(self.prodots[other])
return True, dotfiles
def _parse_actions(self, entries):
def _parse_actions(self, entries, profile=None):
"""parse actions specified for an element
where entries are the ones defined for this dotfile"""
res = {
self.key_actions_pre: [],
self.key_actions_post: [],
}
vars = self.get_variables(profile, debug=self.debug)
t = Templategen(variables=vars)
for line in entries:
fields = shlex.split(line)
entry = fields[0]
args = []
if len(fields) > 1:
args = fields[1:]
tmpargs = fields[1:]
args = []
# template args
for arg in tmpargs:
args.append(t.generate_string(arg))
action = None
if self.key_actions_pre in self.actions and \
entry in self.actions[self.key_actions_pre]: