Clean up scripts

This commit is contained in:
Jonathan Wong 2016-01-12 21:38:47 -08:00
commit 3d6f89d309
5 changed files with 33 additions and 54 deletions

View file

@ -516,6 +516,8 @@ def build_notify_text(session=None, timeline=None, state=None):
available_params = {'server_name': server_name,
'server_uptime': server_uptime,
'streams': stream_count,
'action': state,
'user': user,
'platform': platform,
'player': player,
@ -564,9 +566,7 @@ def build_notify_text(session=None, timeline=None, state=None):
'summary': metadata['summary'],
'tagline': metadata['tagline'],
'rating': metadata['rating'],
'duration': duration,
'action': state,
'streams': stream_count
'duration': duration
}
# Default subject text
@ -780,6 +780,7 @@ def build_server_notify_text(state=None):
on_extup_body = plexpy.CONFIG.NOTIFY_ON_EXTUP_BODY_TEXT
on_intup_subject = plexpy.CONFIG.NOTIFY_ON_INTUP_SUBJECT_TEXT
on_intup_body = plexpy.CONFIG.NOTIFY_ON_INTUP_BODY_TEXT
script_args_text = plexpy.CONFIG.NOTIFY_SCRIPTS_ARGS_TEXT
available_params = {'server_name': server_name,
'server_uptime': server_uptime,
@ -790,7 +791,6 @@ def build_server_notify_text(state=None):
# Default scripts args
script_args = []
script_args_text = plexpy.CONFIG.NOTIFY_SCRIPTS_ARGS_TEXT
# Regex to match {param} but not "{param}"
params_to_quote = re.compile(r'(?<!\")([\{][^}]+[\}])(?!\"\})')

View file

@ -1762,9 +1762,9 @@ class Scripts(object):
notify_action(string): 'play'
script_args(list): ["python2", '-p', '-zomg']
"""
logger.debug(u'Trying to run notify script subject: %s message: %s, action: %s script_args: %s' %
logger.debug(u"PlexPy Notifiers :: Trying to run notify script, subject: %s, message: %s, action: %s, script_args: %s" %
(subject, message, notify_action, script_args))
prefix = ''
script = kwargs.get('script', '') # for manual scripts
@ -1808,7 +1808,7 @@ class Scripts(object):
# Dont try to run the script
# if the action does not have one
if not script:
logger.debug(u'%s has no script, exiting..' % notify_action)
logger.debug(u"PlexPy Notifiers :: Action %s has no script, exiting..." % notify_action)
return
name, ext = os.path.splitext(script)
@ -1847,7 +1847,7 @@ class Scripts(object):
script.extend(script_args)
logger.debug(u'Full script is %s' % script)
logger.debug(u"PlexPy Notifiers :: Full script is: %s" % ' '.join(script))
try:
p = subprocess.Popen(script, stdin=subprocess.PIPE,
@ -1860,14 +1860,16 @@ class Scripts(object):
if out and status:
out = out.strip()
logger.debug(u'%s returned %s' % (script, out))
logger.debug(u"PlexPy Notifiers :: Script returned %s" % out)
if error:
error = error.strip()
logger.error(u'%s' % error)
logger.error(u"PlexPy Notifiers :: Script error: %s" % error)
else:
logger.info(u"PlexPy Notifiers :: Script notification sent.")
except OSError as out:
logger.error(u'Failed to run %s error %s' % (script, out))
except OSError as e:
logger.error(u"PlexPy Notifiers :: Failed to run script: %s" % e)
def return_config_options(self):
config_option = [{'label': 'Script folder',

View file

@ -663,7 +663,6 @@ class WebInterface(object):
@cherrypy.expose
def test_notifier(self, config_id=None, subject='PlexPy', body='Test notification', **kwargs):
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
print kwargs
if config_id.isdigit():
agents = notifiers.available_notification_agents()
@ -1422,12 +1421,6 @@ class WebInterface(object):
return serve_template(templatename="notification_triggers_modal.html", title="Notification Triggers",
data=this_agent)
@cherrypy.expose
def testScripts(self, *args, **kwargs):
''' Used for manual testing for now cba with adding buttion '''
script = notifiers.Scripts()
return script.test(*args, **kwargs)
@cherrypy.expose
def delete_history_rows(self, row_id, **kwargs):
data_factory = datafactory.DataFactory()