mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 19:44:45 +00:00
improve transformation
This commit is contained in:
@@ -5,6 +5,7 @@ Represent an action in dotdrop
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
# local imports
|
||||
from dotdrop.logger import Logger
|
||||
@@ -12,29 +13,37 @@ from dotdrop.logger import Logger
|
||||
|
||||
class Action:
|
||||
|
||||
|
||||
def __init__(self, key, action):
|
||||
self.key = key
|
||||
self.action = action
|
||||
self.log = Logger()
|
||||
|
||||
def execute(self):
|
||||
ret = 1
|
||||
self.log.sub('executing \"%s\"' % (self.action))
|
||||
try:
|
||||
subprocess.call(self.action, shell=True)
|
||||
ret = subprocess.call(self.action, shell=True)
|
||||
except KeyboardInterrupt:
|
||||
self.log.warn('action interrupted')
|
||||
return ret == 0
|
||||
|
||||
def transform(self, arg0, arg1):
|
||||
'''execute transformation with {0} and {1}
|
||||
where {0} is the file to transform and
|
||||
{1} is the result file'''
|
||||
if os.path.exists(arg1):
|
||||
msg = 'transformation destination exists: %s'
|
||||
self.log.warn(msg % (arg1))
|
||||
return False
|
||||
ret = 1
|
||||
cmd = self.action.format(arg0, arg1)
|
||||
self.log.sub('transforming with \"%s\"' % (cmd))
|
||||
try:
|
||||
subprocess.call(cmd, shell=True)
|
||||
ret = subprocess.call(cmd, shell=True)
|
||||
except KeyboardInterrupt:
|
||||
self.log.warn('action interrupted')
|
||||
return arg1
|
||||
return ret == 0
|
||||
|
||||
def __str__(self):
|
||||
return 'key:%s -> \"%s\"' % (self.key, self.action)
|
||||
|
||||
Reference in New Issue
Block a user