Clean up scripts

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

View file

@ -80,38 +80,29 @@ from plexpy import helpers
<p class="help-block">Set a custom body.</p> <p class="help-block">Set a custom body.</p>
</div> </div>
%if agent['name'] == 'Scripts': %if agent['name'] == 'Scripts':
<div class="form-group">
<label for="test_script">Script path</label>
<select class="form-control" id="test_script" name="test_script" >
% for key, value in sorted(data[1]['select_options'].iteritems()):
<option value="${key}">${value}</option>
% endfor
</select>
<p class="help-block">Pick your script</p>
</div>
<div class="form-group"> <div class="form-group">
<label for="test_script_action">Script action</label> <label for="test_script_action">Script action</label>
<select class="form-control" id="test_script_action" name="test_script_action"> <select class="form-control" id="test_script_action" name="test_script_action">
<option value=""></option> <option value=""></option>
<option value="buffer">Buffer warning</option>
<option value="watched">Watched</option>
<option value="play">Playback start</option> <option value="play">Playback start</option>
<option value="pause">Playback stopp</option>
<option value="resume">Playback resume</option>
<option value="stop">Playback stop</option> <option value="stop">Playback stop</option>
<option value="extdown">Plex Server Remote Down</option> <option value="pause">Playback pause</option>
<option value="extup">Plex Server Remote Up</option> <option value="resume">Playback resume</option>
<option value="intdown">Plex Server Down</option> <option value="watched">Watched</option>
<option value="intup">Plex Server Up</option> <option value="buffer">Buffer warnings</option>
<option value="created">Recently added</option> <option value="created">Recently added</option>
<option value="extdown">Plex remote access down</option>
<option value="intdown">Plex server down</option>
<option value="extup">Plex remote access back up</option>
<option value="intup">Plex server back up</option>
</select> </select>
<p class="help-block">Pick your action</p> <p class="help-block">Choose a notification action.</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="test_script_args">Script args</label> <label for="test_script_args">Script args</label>
<input class="form-control" type="text" id="test_script_args" name="test_script_args" value=""> <input class="form-control" type="text" id="test_script_args" name="test_script_args" value="">
<p class="help-block">Set a custom script args: -zomg --x.</p> <p class="help-block">Set custom script arguments: -zomg --x.</p>
</div> </div>
% endif % endif
<div class="form-group"> <div class="form-group">
@ -185,7 +176,6 @@ from plexpy import helpers
subject: $('#test_subject').val(), subject: $('#test_subject').val(),
body: $('#test_body').val(), body: $('#test_body').val(),
notify_action: $('#test_script_action').val(), notify_action: $('#test_script_action').val(),
script: $('#test_script').val(),
script_args: $('#test_script_args').val() }, script_args: $('#test_script_args').val() },
cache: false, cache: false,
async: true, async: true,
@ -196,13 +186,7 @@ from plexpy import helpers
}); });
}); });
$('#pushbullet_apikey, #pushover_apitoken').on('change', function () { $('#pushbullet_apikey, #pushover_apitoken, #scripts_folder').on('change', function () {
doAjaxCall('set_notification_config', $(this), 'tabs', true);
reloadModal();
return false;
});
$('#scripts_folder').on('change', function () {
doAjaxCall('set_notification_config', $(this), 'tabs', true); doAjaxCall('set_notification_config', $(this), 'tabs', true);
reloadModal(); reloadModal();
return false; return false;

View file

@ -1014,6 +1014,14 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr>
<td><strong>{streams}</strong></td>
<td>The number of concurrent streams.</td>
</tr>
<tr>
<td><strong>{action}</strong></td>
<td>The action that triggered the notification.</td>
</tr>
<tr> <tr>
<td><strong>{user}</strong></td> <td><strong>{user}</strong></td>
<td>The username of the person streaming.</td> <td>The username of the person streaming.</td>
@ -1126,14 +1134,6 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<td><strong>{transcode_audio_channels}</strong></td> <td><strong>{transcode_audio_channels}</strong></td>
<td>The audio channels of the transcoded media.</td> <td>The audio channels of the transcoded media.</td>
</tr> </tr>
<tr>
<td><strong>{streams}</strong></td>
<td>The number of concurrent streams.</td>
</tr>
<tr>
<td><strong>{action}</strong></td>
<td>The action that trigged the notification.</td>
</tr>
</tbody> </tbody>
</table> </table>
<table class="notification-params"> <table class="notification-params">

View file

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

View file

@ -1762,7 +1762,7 @@ class Scripts(object):
notify_action(string): 'play' notify_action(string): 'play'
script_args(list): ["python2", '-p', '-zomg'] 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)) (subject, message, notify_action, script_args))
prefix = '' prefix = ''
@ -1808,7 +1808,7 @@ class Scripts(object):
# Dont try to run the script # Dont try to run the script
# if the action does not have one # if the action does not have one
if not script: 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 return
name, ext = os.path.splitext(script) name, ext = os.path.splitext(script)
@ -1847,7 +1847,7 @@ class Scripts(object):
script.extend(script_args) script.extend(script_args)
logger.debug(u'Full script is %s' % script) logger.debug(u"PlexPy Notifiers :: Full script is: %s" % ' '.join(script))
try: try:
p = subprocess.Popen(script, stdin=subprocess.PIPE, p = subprocess.Popen(script, stdin=subprocess.PIPE,
@ -1860,14 +1860,16 @@ class Scripts(object):
if out and status: if out and status:
out = out.strip() out = out.strip()
logger.debug(u'%s returned %s' % (script, out)) logger.debug(u"PlexPy Notifiers :: Script returned %s" % out)
if error: if error:
error = error.strip() 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: except OSError as e:
logger.error(u'Failed to run %s error %s' % (script, out)) logger.error(u"PlexPy Notifiers :: Failed to run script: %s" % e)
def return_config_options(self): def return_config_options(self):
config_option = [{'label': 'Script folder', config_option = [{'label': 'Script folder',

View file

@ -663,7 +663,6 @@ class WebInterface(object):
@cherrypy.expose @cherrypy.expose
def test_notifier(self, config_id=None, subject='PlexPy', body='Test notification', **kwargs): 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" cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
print kwargs
if config_id.isdigit(): if config_id.isdigit():
agents = notifiers.available_notification_agents() agents = notifiers.available_notification_agents()
@ -1422,12 +1421,6 @@ class WebInterface(object):
return serve_template(templatename="notification_triggers_modal.html", title="Notification Triggers", return serve_template(templatename="notification_triggers_modal.html", title="Notification Triggers",
data=this_agent) 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 @cherrypy.expose
def delete_history_rows(self, row_id, **kwargs): def delete_history_rows(self, row_id, **kwargs):
data_factory = datafactory.DataFactory() data_factory = datafactory.DataFactory()