mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 05:34:17 +00:00
allow to have dynamic dotfile actions for #120
This commit is contained in:
@@ -306,7 +306,12 @@ class Cfg:
|
|||||||
# parse actions
|
# parse actions
|
||||||
itsactions = v[self.key_dotfiles_actions] if \
|
itsactions = v[self.key_dotfiles_actions] if \
|
||||||
self.key_dotfiles_actions in v else []
|
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
|
# parse read transformation
|
||||||
itstrans_r = v[self.key_dotfiles_trans_r] if \
|
itstrans_r = v[self.key_dotfiles_trans_r] if \
|
||||||
@@ -540,19 +545,25 @@ class Cfg:
|
|||||||
dotfiles.extend(self.prodots[other])
|
dotfiles.extend(self.prodots[other])
|
||||||
return True, dotfiles
|
return True, dotfiles
|
||||||
|
|
||||||
def _parse_actions(self, entries):
|
def _parse_actions(self, entries, profile=None):
|
||||||
"""parse actions specified for an element
|
"""parse actions specified for an element
|
||||||
where entries are the ones defined for this dotfile"""
|
where entries are the ones defined for this dotfile"""
|
||||||
res = {
|
res = {
|
||||||
self.key_actions_pre: [],
|
self.key_actions_pre: [],
|
||||||
self.key_actions_post: [],
|
self.key_actions_post: [],
|
||||||
}
|
}
|
||||||
|
vars = self.get_variables(profile, debug=self.debug)
|
||||||
|
t = Templategen(variables=vars)
|
||||||
for line in entries:
|
for line in entries:
|
||||||
fields = shlex.split(line)
|
fields = shlex.split(line)
|
||||||
entry = fields[0]
|
entry = fields[0]
|
||||||
args = []
|
args = []
|
||||||
if len(fields) > 1:
|
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
|
action = None
|
||||||
if self.key_actions_pre in self.actions and \
|
if self.key_actions_pre in self.actions and \
|
||||||
entry in self.actions[self.key_actions_pre]:
|
entry in self.actions[self.key_actions_pre]:
|
||||||
|
|||||||
Reference in New Issue
Block a user