|
|
@ -1,38 +1,48 @@ |
|
|
|
import traceback |
|
|
|
import subprocess |
|
|
|
import os |
|
|
|
|
|
|
|
from couchpotato.core.helpers.encoding import toUnicode |
|
|
|
from couchpotato.core.helpers.variable import getIdentifier |
|
|
|
from couchpotato.api import addApiView |
|
|
|
from couchpotato.core.event import addEvent |
|
|
|
from couchpotato.core.logger import CPLog |
|
|
|
from couchpotato.core.notifications.base import Notification |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log = CPLog(__name__) |
|
|
|
|
|
|
|
autoload = 'Script' |
|
|
|
|
|
|
|
class Script(Notification): |
|
|
|
|
|
|
|
def notify(self, message = '', data = None, listener = None): |
|
|
|
if not data: data = {} |
|
|
|
def __init__(self): |
|
|
|
addApiView(self.testNotifyName(), self.test) |
|
|
|
|
|
|
|
script_data = { |
|
|
|
'message': toUnicode(message) |
|
|
|
} |
|
|
|
addEvent('renamer.after', self.runScript) |
|
|
|
|
|
|
|
if getIdentifier(data): |
|
|
|
script_data.update({ |
|
|
|
'imdb_id': getIdentifier(data) |
|
|
|
}) |
|
|
|
def runScript(self, message = None, group = None): |
|
|
|
if self.isDisabled(): return |
|
|
|
if not group: group = {} |
|
|
|
|
|
|
|
command = [self.conf('path'), group.get('destination_dir')] |
|
|
|
log.info('Executing script command: %s ', command) |
|
|
|
try: |
|
|
|
subprocess.call([self.conf('path'), message]) |
|
|
|
p = subprocess.Popen(command, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) |
|
|
|
out = p.communicate() |
|
|
|
log.info('Result from script: %s', str(out)) |
|
|
|
return True |
|
|
|
except: |
|
|
|
log.error('Script notification failed: %s', traceback.format_exc()) |
|
|
|
except OSError as e: |
|
|
|
log.error('Unable to run script: %s', e) |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
def test(self, **kwargs): |
|
|
|
return { |
|
|
|
'success': os.path.isfile(self.conf('path')) |
|
|
|
} |
|
|
|
|
|
|
|
config = [{ |
|
|
|
'name': 'script', |
|
|
|