From 7f2294ee8b571d05eff6553a4a217a8f4175fd6b Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 4 Feb 2019 21:57:31 +0100 Subject: [PATCH] adding more info on actions with verbose (#83) --- dotdrop/action.py | 7 ++++++- dotdrop/config.py | 16 +++++++++------- tests-ng/actions-args.sh | 2 +- tests/test_install.py | 5 +++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/dotdrop/action.py b/dotdrop/action.py index 414b420..93a2b06 100644 --- a/dotdrop/action.py +++ b/dotdrop/action.py @@ -32,10 +32,15 @@ class Cmd: class Action(Cmd): - def __init__(self, key, action, *args): + def __init__(self, key, kind, action, *args): super(Action, self).__init__(key, action) + self.kind = kind self.args = args + def __str__(self): + out = '{}: \"{}\" with args: {}' + return out.format(self.key, self.action, self.args) + def execute(self): """execute the action in the shell""" ret = 1 diff --git a/dotdrop/config.py b/dotdrop/config.py index be71463..66dcc1f 100644 --- a/dotdrop/config.py +++ b/dotdrop/config.py @@ -181,12 +181,14 @@ class Cfg: for k2, v2 in items: if k not in self.actions: self.actions[k] = {} - self.actions[k][k2] = Action(k2, v2) + self.actions[k][k2] = Action(k2, k, v2) else: # parse naked actions as post actions if self.key_actions_post not in self.actions: self.actions[self.key_actions_post] = {} - self.actions[self.key_actions_post][k] = Action(k, v) + self.actions[self.key_actions_post][k] = Action(k, + '', + v) # parse read transformations if self.key_trans_r in self.content: @@ -383,24 +385,24 @@ class Cfg: action = None if self.key_actions_pre in self.actions and \ entry in self.actions[self.key_actions_pre]: - key = self.key_actions_pre + kind = self.key_actions_pre if not args: action = self.actions[self.key_actions_pre][entry] else: a = self.actions[self.key_actions_pre][entry].action - action = Action(key, a, *args) + action = Action(entry, kind, a, *args) elif self.key_actions_post in self.actions and \ entry in self.actions[self.key_actions_post]: - key = self.key_actions_post + kind = self.key_actions_post if not args: action = self.actions[self.key_actions_post][entry] else: a = self.actions[self.key_actions_post][entry].action - action = Action(key, a, *args) + action = Action(entry, kind, a, *args) else: self.log.warn('unknown action \"{}\"'.format(entry)) continue - res[key].append(action) + res[kind].append(action) return res def _parse_trans(self, trans, read=True): diff --git a/tests-ng/actions-args.sh b/tests-ng/actions-args.sh index 571c885..1baa226 100755 --- a/tests-ng/actions-args.sh +++ b/tests-ng/actions-args.sh @@ -90,7 +90,7 @@ cat ${cfg} echo "test" > ${tmps}/dotfiles/abc # install -cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 +cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 --verbose # checks [ ! -e ${tmpa}/pre ] && echo "pre arg action not found" && exit 1 diff --git a/tests/test_install.py b/tests/test_install.py index fee14c3..4762a9c 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -149,7 +149,8 @@ exec bspwm # to test actions value = get_string(12) fact = '/tmp/action' - act1 = Action('testaction', 'echo "{}" > {}'.format(value, fact)) + act1 = Action('testaction', 'post', 'echo "{}" > {}'.format(value, + fact)) f8, c8 = create_random_file(tmp) dst8 = os.path.join(dst, get_string(6)) d8 = Dotfile(get_string(6), dst8, os.path.basename(f8), actions=[act1]) @@ -158,7 +159,7 @@ exec bspwm trans1 = 'trans1' trans2 = 'trans2' cmd = 'cat {0} | sed \'s/%s/%s/g\' > {1}' % (trans1, trans2) - tr = Action('testtrans', cmd) + tr = Action('testtrans', 'post', cmd) f9, c9 = create_random_file(tmp, content=trans1) dst9 = os.path.join(dst, get_string(6)) d9 = Dotfile(get_string(6), dst9, os.path.basename(f9), trans_r=tr)