From 1888a09ad7ddc4f011fdc44eea854e14a5605cf3 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 19 Jun 2019 16:07:29 +0200 Subject: [PATCH] fix action usage variable expansion --- dotdrop/action.py | 10 +++++++--- dotdrop/dotdrop.py | 4 ++-- tests-ng/actions-args-template.sh | 21 +++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/dotdrop/action.py b/dotdrop/action.py index daf1545..072d9dd 100644 --- a/dotdrop/action.py +++ b/dotdrop/action.py @@ -86,18 +86,22 @@ class Action(Cmd): def __repr__(self): return 'action({})'.format(self.__str__()) - def execute(self, templater=None): + def execute(self, templater=None, debug=False): """execute the action in the shell""" ret = 1 action = self.action if templater: action = templater.generate_string(self.action) + if debug: + self.log.dbg('action \"{}\" -> \"{}\"'.format(self.action, + action)) cmd = action + args = [templater.generate_string(a) for a in self.args] try: - cmd = action.format(*self.args) + cmd = action.format(*args) except IndexError: err = 'bad action: \"{}\"'.format(action) - err += ' with \"{}\"'.format(self.args) + err += ' with \"{}\"'.format(args) self.log.warn(err) return False self.log.sub('executing \"{}\"'.format(cmd)) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index d807b6f..d521d85 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -46,7 +46,7 @@ def action_executor(o, actions, defactions, templater, post=False): continue if o.debug: LOG.dbg('executing def-{}-action {}'.format(s, action)) - ret = action.execute(templater=templater) + ret = action.execute(templater=templater, debug=o.debug) if not ret: err = 'def-{}-action \"{}\" failed'.format(s, action.key) LOG.err(err) @@ -59,7 +59,7 @@ def action_executor(o, actions, defactions, templater, post=False): continue if o.debug: LOG.dbg('executing {}-action {}'.format(s, action)) - ret = action.execute(templater=templater) + ret = action.execute(templater=templater, debug=o.debug) if not ret: err = '{}-action \"{}\" failed'.format(s, action.key) LOG.err(err) diff --git a/tests-ng/actions-args-template.sh b/tests-ng/actions-args-template.sh index 944f1f8..9f026ec 100755 --- a/tests-ng/actions-args-template.sh +++ b/tests-ng/actions-args-template.sh @@ -85,10 +85,10 @@ profiles: - profileaction '{{@@ var_profile @@}}' - dynaction '{{@@ user_name @@}}' variables: - var_pre: var_pre - var_post: var_post - var_naked: var_naked - var_profile: var_profile + var_pre: abc + var_post: def + var_naked: ghi + var_profile: jkl dynvariables: user_name: 'echo $USER' _EOF @@ -106,10 +106,15 @@ cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V [ ! -e ${tmpa}/naked ] && echo 'naked action not executed' && exit 1 [ ! -e ${tmpa}/profile ] && echo 'profile action not executed' && exit 1 [ ! -e ${tmpa}/dyn ] && echo 'dynamic acton action not executed' && exit 1 -grep var_pre ${tmpa}/pre >/dev/null -grep var_post ${tmpa}/post >/dev/null -grep var_naked ${tmpa}/naked >/dev/null -grep var_profile ${tmpa}/profile >/dev/null +cat ${tmpa}/pre +grep abc ${tmpa}/pre >/dev/null +cat ${tmpa}/post +grep def ${tmpa}/post >/dev/null +cat ${tmpa}/naked +grep ghi ${tmpa}/naked >/dev/null +cat ${tmpa}/profile +grep jkl ${tmpa}/profile >/dev/null +cat ${tmpa}/dyn grep "$USER" ${tmpa}/dyn >/dev/null ## CLEANING