mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 07:44:16 +00:00
action with arguments for #59
This commit is contained in:
@@ -32,12 +32,23 @@ class Cmd:
|
||||
|
||||
class Action(Cmd):
|
||||
|
||||
def __init__(self, key, action, *args):
|
||||
super(Action, self).__init__(key, action)
|
||||
self.args = args
|
||||
|
||||
def execute(self):
|
||||
"""execute the action in the shell"""
|
||||
ret = 1
|
||||
self.log.sub('executing \"{}\"'.format(self.action))
|
||||
try:
|
||||
ret = subprocess.call(self.action, shell=True)
|
||||
cmd = self.action.format(*self.args)
|
||||
except IndexError:
|
||||
err = 'bad action: \"{}\"'.format(self.action)
|
||||
err += ' with \"{}\"'.format(self.args)
|
||||
self.log.warn(err)
|
||||
return False
|
||||
self.log.sub('executing \"{}\"'.format(cmd))
|
||||
try:
|
||||
ret = subprocess.call(cmd, shell=True)
|
||||
except KeyboardInterrupt:
|
||||
self.log.warn('action interrupted')
|
||||
return ret == 0
|
||||
|
||||
@@ -258,16 +258,29 @@ class Cfg:
|
||||
self.key_actions_pre: [],
|
||||
self.key_actions_post: [],
|
||||
}
|
||||
for entry in entries:
|
||||
for line in entries:
|
||||
fields = line.split(' ')
|
||||
entry = fields[0]
|
||||
args = []
|
||||
if len(fields) > 1:
|
||||
args = fields[1:]
|
||||
action = None
|
||||
if self.key_actions_pre in self.actions and \
|
||||
entry in self.actions[self.key_actions_pre]:
|
||||
key = self.key_actions_pre
|
||||
action = self.actions[self.key_actions_pre][entry]
|
||||
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)
|
||||
elif self.key_actions_post in self.actions and \
|
||||
entry in self.actions[self.key_actions_post]:
|
||||
key = self.key_actions_post
|
||||
action = self.actions[self.key_actions_post][entry]
|
||||
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)
|
||||
else:
|
||||
self.log.warn('unknown action \"{}\"'.format(entry))
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user