2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-12-29 03:21:58 +00:00
|
|
|
"""
|
|
|
|
Test Library Functions
|
|
|
|
"""
|
2017-01-09 04:40:39 +00:00
|
|
|
import datetime, sys
|
2016-04-04 03:17:29 +00:00
|
|
|
from plexapi.client import PlexClient
|
|
|
|
from plexapi.exceptions import NotFound
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2017-01-09 04:40:39 +00:00
|
|
|
REGISTERED = []
|
2016-03-15 15:04:53 +00:00
|
|
|
COLORS = {'blue':'\033[94m', 'green':'\033[92m', 'red':'\033[91m', 'yellow':'\033[93m', 'end':'\033[0m'}
|
|
|
|
|
|
|
|
|
2017-01-09 04:40:39 +00:00
|
|
|
def register():
|
|
|
|
def wrapper(func):
|
|
|
|
name = '%s/%s' % (func.__module__, func.__name__)
|
|
|
|
REGISTERED.append({'func':func, 'name':name})
|
|
|
|
return lambda plex, account: func(plex, account)
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
def itertests(query):
|
|
|
|
for test in REGISTERED:
|
|
|
|
if not query:
|
|
|
|
yield test
|
|
|
|
elif query in test['name']:
|
|
|
|
yield test
|
2014-12-29 03:21:58 +00:00
|
|
|
|
2015-06-09 04:17:55 +00:00
|
|
|
|
|
|
|
def log(indent, message, color=None):
|
2014-12-29 03:21:58 +00:00
|
|
|
dt = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
2015-06-09 04:17:55 +00:00
|
|
|
if color:
|
2016-03-15 15:04:53 +00:00
|
|
|
return sys.stdout.write('%s: %s%s%s%s\n' % (dt, ' '*indent, COLORS[color], message, COLORS['end']))
|
|
|
|
return sys.stdout.write('%s: %s%s\n' % (dt, ' '*indent, message))
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
|
2017-01-09 04:40:39 +00:00
|
|
|
def getclient(name, baseurl, server):
|
2016-04-04 03:17:29 +00:00
|
|
|
try:
|
|
|
|
return server.client(name)
|
|
|
|
except NotFound as err:
|
|
|
|
log(2, 'Warning: %s' % err)
|
|
|
|
return PlexClient(baseurl, server=server)
|
|
|
|
|