mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 00:06:07 -07:00
Helper function for splitting script args
This commit is contained in:
parent
f0e2355231
commit
ae2584b6f6
3 changed files with 13 additions and 10 deletions
|
@ -33,6 +33,7 @@ import maxminddb
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shlex
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -1137,3 +1138,12 @@ def traverse_map(obj, func):
|
||||||
new_obj = func(obj)
|
new_obj = func(obj)
|
||||||
|
|
||||||
return new_obj
|
return new_obj
|
||||||
|
|
||||||
|
|
||||||
|
def split_args(args=None):
|
||||||
|
if isinstance(args, list):
|
||||||
|
return args
|
||||||
|
elif isinstance(args, basestring):
|
||||||
|
return [arg.decode(plexpy.SYS_ENCODING, 'ignore')
|
||||||
|
for arg in shlex.split(args.encode(plexpy.SYS_ENCODING, 'ignore'))]
|
||||||
|
return []
|
||||||
|
|
|
@ -23,7 +23,6 @@ import json
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shlex
|
|
||||||
from string import Formatter
|
from string import Formatter
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
@ -337,12 +336,7 @@ def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data
|
||||||
if notify_action in ('test', 'api'):
|
if notify_action in ('test', 'api'):
|
||||||
subject = kwargs.pop('subject', 'Tautulli')
|
subject = kwargs.pop('subject', 'Tautulli')
|
||||||
body = kwargs.pop('body', 'Test Notification')
|
body = kwargs.pop('body', 'Test Notification')
|
||||||
script_args = kwargs.pop('script_args', [])
|
script_args = helpers.split_args(kwargs.pop('script_args', []))
|
||||||
|
|
||||||
if script_args and isinstance(script_args, basestring):
|
|
||||||
# Attemps to format test script args for the user
|
|
||||||
script_args = [arg.decode(plexpy.SYS_ENCODING, 'ignore')
|
|
||||||
for arg in shlex.split(script_args.encode(plexpy.SYS_ENCODING, 'ignore'))]
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Get the subject and body strings
|
# Get the subject and body strings
|
||||||
|
@ -1050,8 +1044,7 @@ def build_notify_text(subject='', body='', notify_action=None, parameters=None,
|
||||||
|
|
||||||
if agent_id == 15:
|
if agent_id == 15:
|
||||||
try:
|
try:
|
||||||
script_args = [custom_formatter.format(arg.decode(plexpy.SYS_ENCODING, 'ignore'), **parameters)
|
script_args = [custom_formatter.format(arg, **parameters) for arg in helpers.split_args(subject)]
|
||||||
for arg in shlex.split(subject.encode(plexpy.SYS_ENCODING, 'ignore'))]
|
|
||||||
except LookupError as e:
|
except LookupError as e:
|
||||||
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in script argument. Using fallback." % e)
|
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in script argument. Using fallback." % e)
|
||||||
script_args = []
|
script_args = []
|
||||||
|
|
|
@ -3078,7 +3078,7 @@ class SCRIPTS(Notifier):
|
||||||
logger.error(u"Tautulli Notifiers :: No script folder specified.")
|
logger.error(u"Tautulli Notifiers :: No script folder specified.")
|
||||||
return
|
return
|
||||||
|
|
||||||
script_args = kwargs.get('script_args', [])
|
script_args = helpers.split_args(kwargs.get('script_args', subject))
|
||||||
|
|
||||||
logger.debug(u"Tautulli Notifiers :: Trying to run notify script, action: %s, arguments: %s"
|
logger.debug(u"Tautulli Notifiers :: Trying to run notify script, action: %s, arguments: %s"
|
||||||
% (action, script_args))
|
% (action, script_args))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue