Merge pull request #498 from Hellowlol/ps1

add support for powershell
This commit is contained in:
JonnyWong16 2016-01-30 15:54:34 -08:00
commit b1a2cf33d8

View file

@ -34,7 +34,7 @@ from pynma import pynma
import gntp.notifier import gntp.notifier
import oauth2 as oauth import oauth2 as oauth
import pythontwitter as twitter import pythontwitter as twitter
import pythonfacebook as facebook import pythonfacebook as facebook
import plexpy import plexpy
from plexpy import logger, helpers, request from plexpy import logger, helpers, request
@ -58,7 +58,7 @@ AGENT_IDS = {"Growl": 0,
"Scripts": 15, "Scripts": 15,
"Facebook": 16} "Facebook": 16}
def available_notification_agents(): def available_notification_agents():
agents = [{'name': 'Growl', agents = [{'name': 'Growl',
'id': AGENT_IDS['Growl'], 'id': AGENT_IDS['Growl'],
@ -1777,7 +1777,7 @@ class SLACK(object):
class Scripts(object): class Scripts(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.script_exts = ('.bat', '.cmd', '.exe', '.php', '.pl', '.py', '.pyw', '.rb', '.sh') self.script_exts = ('.bat', '.cmd', '.exe', '.php', '.pl', '.py', '.pyw', '.rb', '.sh', '.ps1')
def conf(self, options): def conf(self, options):
return cherrypy.config['config'].get('Scripts', options) return cherrypy.config['config'].get('Scripts', options)
@ -1807,7 +1807,7 @@ class Scripts(object):
return scripts return scripts
def notify(self, subject='', message='', notify_action='', script_args=[], *args, **kwargs): def notify(self, subject='', message='', notify_action='', script_args=None, *args, **kwargs):
""" """
Args: Args:
subject(string, optional): Head text, subject(string, optional): Head text,
@ -1817,7 +1817,10 @@ class Scripts(object):
""" """
logger.debug(u"PlexPy Notifiers :: Trying to run notify script, action: %s, arguments: %s" % logger.debug(u"PlexPy Notifiers :: Trying to run notify script, action: %s, arguments: %s" %
(notify_action if notify_action else None, script_args if script_args else None)) (notify_action if notify_action else None, script_args if script_args else None))
if script_args is None:
script_args = []
if not plexpy.CONFIG.SCRIPTS_FOLDER: if not plexpy.CONFIG.SCRIPTS_FOLDER:
return return
@ -1879,6 +1882,8 @@ class Scripts(object):
prefix = 'perl' prefix = 'perl'
elif ext == '.rb': elif ext == '.rb':
prefix = 'ruby' prefix = 'ruby'
elif ext == '.ps1':
prefix = 'powershell -executionPolicy bypass -file'
else: else:
prefix = '' prefix = ''
@ -1886,7 +1891,10 @@ class Scripts(object):
script = script.encode(plexpy.SYS_ENCODING, 'ignore') script = script.encode(plexpy.SYS_ENCODING, 'ignore')
if prefix: if prefix:
script = [prefix, script] if ext == '.ps1':
script = prefix.split() + [script]
else:
script = [prefix, script]
else: else:
script = [script] script = [script]
@ -2025,7 +2033,7 @@ class Scripts(object):
return config_option return config_option
class FacebookNotifier(object): class FacebookNotifier(object):
def __init__(self): def __init__(self):
@ -2050,7 +2058,7 @@ class FacebookNotifier(object):
def _get_credentials(self, code): def _get_credentials(self, code):
logger.info(u"PlexPy Notifiers :: Requesting access token from Facebook") logger.info(u"PlexPy Notifiers :: Requesting access token from Facebook")
try: try:
# Request user access token # Request user access token
api = facebook.GraphAPI(version='2.5') api = facebook.GraphAPI(version='2.5')
@ -2059,19 +2067,19 @@ class FacebookNotifier(object):
app_id=self.app_id, app_id=self.app_id,
app_secret=self.app_secret) app_secret=self.app_secret)
access_token = response['access_token'] access_token = response['access_token']
# Request extended user access token # Request extended user access token
api = facebook.GraphAPI(access_token=access_token, version='2.5') api = facebook.GraphAPI(access_token=access_token, version='2.5')
response = api.extend_access_token(app_id=self.app_id, response = api.extend_access_token(app_id=self.app_id,
app_secret=self.app_secret) app_secret=self.app_secret)
access_token = response['access_token'] access_token = response['access_token']
plexpy.CONFIG.FACEBOOK_TOKEN = access_token plexpy.CONFIG.FACEBOOK_TOKEN = access_token
plexpy.CONFIG.write() plexpy.CONFIG.write()
except Exception as e: except Exception as e:
logger.error(u"PlexPy Notifiers :: Error requesting Facebook access token: %s" % e) logger.error(u"PlexPy Notifiers :: Error requesting Facebook access token: %s" % e)
return False return False
return True return True
def _post_facebook(self, message=None): def _post_facebook(self, message=None):