Browse Source

Updated script notification to use Popen instead of call.

pull/7204/head
Fmstrat 8 years ago
parent
commit
714a942bc5
  1. 34
      couchpotato/core/notifications/script.py

34
couchpotato/core/notifications/script.py

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

Loading…
Cancel
Save