mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 19:54:17 +00:00
adding a new Transform object to simplify trans/actions logic
This commit is contained in:
@@ -11,13 +11,25 @@ import os
|
||||
from dotdrop.logger import Logger
|
||||
|
||||
|
||||
class Action:
|
||||
class Cmd:
|
||||
|
||||
def __init__(self, key, action):
|
||||
self.key = key
|
||||
self.action = action
|
||||
self.log = Logger()
|
||||
|
||||
def __str__(self):
|
||||
return 'key:{} -> \"{}\"'.format(self.key, self.action)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.key) ^ hash(self.action)
|
||||
|
||||
|
||||
class Action(Cmd):
|
||||
|
||||
def execute(self):
|
||||
ret = 1
|
||||
self.log.sub('executing \"{}\"'.format(self.action))
|
||||
@@ -27,6 +39,9 @@ class Action:
|
||||
self.log.warn('action interrupted')
|
||||
return ret == 0
|
||||
|
||||
|
||||
class Transform(Cmd):
|
||||
|
||||
def transform(self, arg0, arg1):
|
||||
'''execute transformation with {0} and {1}
|
||||
where {0} is the file to transform and
|
||||
@@ -43,12 +58,3 @@ class Action:
|
||||
except KeyboardInterrupt:
|
||||
self.log.warn('action interrupted')
|
||||
return ret == 0
|
||||
|
||||
def __str__(self):
|
||||
return 'key:{} -> \"{}\"'.format(self.key, self.action)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.key) ^ hash(self.action)
|
||||
|
||||
Reference in New Issue
Block a user