1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-09 17:34:16 +00:00

action with arguments for #59

This commit is contained in:
deadc0de6
2018-09-24 20:09:39 +02:00
parent 0d4ce18e49
commit 622fe71f06
3 changed files with 142 additions and 5 deletions

View File

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