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