1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-12 15:19:27 +00:00

fix action usage variable expansion

This commit is contained in:
deadc0de6
2019-06-19 16:07:29 +02:00
parent 44723dc032
commit 1888a09ad7
3 changed files with 22 additions and 13 deletions

View File

@@ -86,18 +86,22 @@ class Action(Cmd):
def __repr__(self): def __repr__(self):
return 'action({})'.format(self.__str__()) return 'action({})'.format(self.__str__())
def execute(self, templater=None): def execute(self, templater=None, debug=False):
"""execute the action in the shell""" """execute the action in the shell"""
ret = 1 ret = 1
action = self.action action = self.action
if templater: if templater:
action = templater.generate_string(self.action) action = templater.generate_string(self.action)
if debug:
self.log.dbg('action \"{}\" -> \"{}\"'.format(self.action,
action))
cmd = action cmd = action
args = [templater.generate_string(a) for a in self.args]
try: try:
cmd = action.format(*self.args) cmd = action.format(*args)
except IndexError: except IndexError:
err = 'bad action: \"{}\"'.format(action) err = 'bad action: \"{}\"'.format(action)
err += ' with \"{}\"'.format(self.args) err += ' with \"{}\"'.format(args)
self.log.warn(err) self.log.warn(err)
return False return False
self.log.sub('executing \"{}\"'.format(cmd)) self.log.sub('executing \"{}\"'.format(cmd))

View File

@@ -46,7 +46,7 @@ def action_executor(o, actions, defactions, templater, post=False):
continue continue
if o.debug: if o.debug:
LOG.dbg('executing def-{}-action {}'.format(s, action)) LOG.dbg('executing def-{}-action {}'.format(s, action))
ret = action.execute(templater=templater) ret = action.execute(templater=templater, debug=o.debug)
if not ret: if not ret:
err = 'def-{}-action \"{}\" failed'.format(s, action.key) err = 'def-{}-action \"{}\" failed'.format(s, action.key)
LOG.err(err) LOG.err(err)
@@ -59,7 +59,7 @@ def action_executor(o, actions, defactions, templater, post=False):
continue continue
if o.debug: if o.debug:
LOG.dbg('executing {}-action {}'.format(s, action)) LOG.dbg('executing {}-action {}'.format(s, action))
ret = action.execute(templater=templater) ret = action.execute(templater=templater, debug=o.debug)
if not ret: if not ret:
err = '{}-action \"{}\" failed'.format(s, action.key) err = '{}-action \"{}\" failed'.format(s, action.key)
LOG.err(err) LOG.err(err)

View File

@@ -85,10 +85,10 @@ profiles:
- profileaction '{{@@ var_profile @@}}' - profileaction '{{@@ var_profile @@}}'
- dynaction '{{@@ user_name @@}}' - dynaction '{{@@ user_name @@}}'
variables: variables:
var_pre: var_pre var_pre: abc
var_post: var_post var_post: def
var_naked: var_naked var_naked: ghi
var_profile: var_profile var_profile: jkl
dynvariables: dynvariables:
user_name: 'echo $USER' user_name: 'echo $USER'
_EOF _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}/naked ] && echo 'naked action not executed' && exit 1
[ ! -e ${tmpa}/profile ] && echo 'profile 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 [ ! -e ${tmpa}/dyn ] && echo 'dynamic acton action not executed' && exit 1
grep var_pre ${tmpa}/pre >/dev/null cat ${tmpa}/pre
grep var_post ${tmpa}/post >/dev/null grep abc ${tmpa}/pre >/dev/null
grep var_naked ${tmpa}/naked >/dev/null cat ${tmpa}/post
grep var_profile ${tmpa}/profile >/dev/null 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 grep "$USER" ${tmpa}/dyn >/dev/null
## CLEANING ## CLEANING