1
0
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:
Ziirish
2018-06-01 22:11:49 +02:00
parent a867a850d8
commit aa3ad5e8ab
4 changed files with 33 additions and 24 deletions

View File

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