mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 13:44:16 +00:00
adding more info on actions with verbose (#83)
This commit is contained in:
@@ -32,10 +32,15 @@ class Cmd:
|
|||||||
|
|
||||||
class Action(Cmd):
|
class Action(Cmd):
|
||||||
|
|
||||||
def __init__(self, key, action, *args):
|
def __init__(self, key, kind, action, *args):
|
||||||
super(Action, self).__init__(key, action)
|
super(Action, self).__init__(key, action)
|
||||||
|
self.kind = kind
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
out = '{}: \"{}\" with args: {}'
|
||||||
|
return out.format(self.key, self.action, self.args)
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
"""execute the action in the shell"""
|
"""execute the action in the shell"""
|
||||||
ret = 1
|
ret = 1
|
||||||
|
|||||||
@@ -181,12 +181,14 @@ class Cfg:
|
|||||||
for k2, v2 in items:
|
for k2, v2 in items:
|
||||||
if k not in self.actions:
|
if k not in self.actions:
|
||||||
self.actions[k] = {}
|
self.actions[k] = {}
|
||||||
self.actions[k][k2] = Action(k2, v2)
|
self.actions[k][k2] = Action(k2, k, v2)
|
||||||
else:
|
else:
|
||||||
# parse naked actions as post actions
|
# parse naked actions as post actions
|
||||||
if self.key_actions_post not in self.actions:
|
if self.key_actions_post not in self.actions:
|
||||||
self.actions[self.key_actions_post] = {}
|
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
|
# parse read transformations
|
||||||
if self.key_trans_r in self.content:
|
if self.key_trans_r in self.content:
|
||||||
@@ -383,24 +385,24 @@ class Cfg:
|
|||||||
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]:
|
||||||
key = self.key_actions_pre
|
kind = self.key_actions_pre
|
||||||
if not args:
|
if not args:
|
||||||
action = self.actions[self.key_actions_pre][entry]
|
action = self.actions[self.key_actions_pre][entry]
|
||||||
else:
|
else:
|
||||||
a = self.actions[self.key_actions_pre][entry].action
|
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 \
|
elif self.key_actions_post in self.actions and \
|
||||||
entry in self.actions[self.key_actions_post]:
|
entry in self.actions[self.key_actions_post]:
|
||||||
key = self.key_actions_post
|
kind = self.key_actions_post
|
||||||
if not args:
|
if not args:
|
||||||
action = self.actions[self.key_actions_post][entry]
|
action = self.actions[self.key_actions_post][entry]
|
||||||
else:
|
else:
|
||||||
a = self.actions[self.key_actions_post][entry].action
|
a = self.actions[self.key_actions_post][entry].action
|
||||||
action = Action(key, a, *args)
|
action = Action(entry, kind, a, *args)
|
||||||
else:
|
else:
|
||||||
self.log.warn('unknown action \"{}\"'.format(entry))
|
self.log.warn('unknown action \"{}\"'.format(entry))
|
||||||
continue
|
continue
|
||||||
res[key].append(action)
|
res[kind].append(action)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _parse_trans(self, trans, read=True):
|
def _parse_trans(self, trans, read=True):
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ cat ${cfg}
|
|||||||
echo "test" > ${tmps}/dotfiles/abc
|
echo "test" > ${tmps}/dotfiles/abc
|
||||||
|
|
||||||
# install
|
# install
|
||||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 --verbose
|
||||||
|
|
||||||
# checks
|
# checks
|
||||||
[ ! -e ${tmpa}/pre ] && echo "pre arg action not found" && exit 1
|
[ ! -e ${tmpa}/pre ] && echo "pre arg action not found" && exit 1
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ exec bspwm
|
|||||||
# to test actions
|
# to test actions
|
||||||
value = get_string(12)
|
value = get_string(12)
|
||||||
fact = '/tmp/action'
|
fact = '/tmp/action'
|
||||||
act1 = Action('testaction', 'echo "{}" > {}'.format(value, fact))
|
act1 = Action('testaction', 'post', 'echo "{}" > {}'.format(value,
|
||||||
|
fact))
|
||||||
f8, c8 = create_random_file(tmp)
|
f8, c8 = create_random_file(tmp)
|
||||||
dst8 = os.path.join(dst, get_string(6))
|
dst8 = os.path.join(dst, get_string(6))
|
||||||
d8 = Dotfile(get_string(6), dst8, os.path.basename(f8), actions=[act1])
|
d8 = Dotfile(get_string(6), dst8, os.path.basename(f8), actions=[act1])
|
||||||
@@ -158,7 +159,7 @@ exec bspwm
|
|||||||
trans1 = 'trans1'
|
trans1 = 'trans1'
|
||||||
trans2 = 'trans2'
|
trans2 = 'trans2'
|
||||||
cmd = 'cat {0} | sed \'s/%s/%s/g\' > {1}' % (trans1, 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)
|
f9, c9 = create_random_file(tmp, content=trans1)
|
||||||
dst9 = os.path.join(dst, get_string(6))
|
dst9 = os.path.join(dst, get_string(6))
|
||||||
d9 = Dotfile(get_string(6), dst9, os.path.basename(f9), trans_r=tr)
|
d9 = Dotfile(get_string(6), dst9, os.path.basename(f9), trans_r=tr)
|
||||||
|
|||||||
Reference in New Issue
Block a user