1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 14:58:48 +00:00

adding more info on actions with verbose (#83)

This commit is contained in:
deadc0de6
2019-02-04 21:57:31 +01:00
parent 9d081957fc
commit 7f2294ee8b
4 changed files with 19 additions and 11 deletions

View File

@@ -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

View File

@@ -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):

View File

@@ -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

View File

@@ -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)