From 73ce4eeacbd6aa80c57f45e9311016012173b050 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 2 Jul 2017 18:57:17 +0200 Subject: [PATCH] Funnel commands to main Python instance --- default.py | 16 +++++++++++++--- resources/lib/command_pipeline.py | 29 ++++++++++++++++++++++++++++- resources/lib/entrypoint.py | 2 +- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/default.py b/default.py index 96983316..4b220874 100644 --- a/default.py +++ b/default.py @@ -137,7 +137,7 @@ class Main(): window('plex_runLibScan', value='del_textures') elif mode == 'chooseServer': - entrypoint.chooseServer() + self.__exec('function=choose_server') elif mode == 'refreshplaylist': log.info('Requesting playlist/nodes refresh') @@ -172,8 +172,7 @@ class Main(): # Put the request into the 'queue' while window('plex_command'): sleep(50) - window('plex_command', - value='play_%s' % argv[2]) + window('plex_command', value='play_%s' % argv[2]) # Wait for the result while not pickl_window('plex_result'): sleep(50) @@ -190,6 +189,17 @@ class Main(): listitem = convert_PKC_to_listitem(result.listitem) setResolvedUrl(HANDLE, True, listitem) + @staticmethod + def __exec(command): + """ + Used to funnel commands to the main PKC python instance (like play()) + """ + # Put the request into the 'queue' + while window('plex_command'): + sleep(50) + window('plex_command', value='exec_%s' % command) + # No need to wait for the result + def deviceid(self): deviceId_old = window('plex_client_Id') from clientinfo import getDeviceId diff --git a/resources/lib/command_pipeline.py b/resources/lib/command_pipeline.py index 64fc799c..efb441e0 100644 --- a/resources/lib/command_pipeline.py +++ b/resources/lib/command_pipeline.py @@ -3,11 +3,13 @@ import logging from threading import Thread from Queue import Queue +from urlparse import parse_qsl from xbmc import sleep from utils import window, thread_methods import state +import entrypoint ############################################################################### log = logging.getLogger("PLEX."+__name__) @@ -32,6 +34,29 @@ class Monitor_Window(Thread): self.playback_queue = Queue() Thread.__init__(self) + @staticmethod + def __execute(value): + """ + Kick off with new threads. Pass in a string with the information url- + encoded: + function= + params= (optional) + """ + values = dict(parse_qsl(value)) + function = values.get('function') + params = values.get('params') + log.debug('Execution called for function %s with parameters %s' + % (function, params)) + function = getattr(entrypoint, function) + try: + if params is not None: + function(params) + else: + function() + except: + log.error('Failed to execute function %s with params %s' + % (function, params)) + def run(self): thread_stopped = self.thread_stopped queue = self.playback_queue @@ -42,7 +67,9 @@ class Monitor_Window(Thread): window('plex_command', clear=True) if value.startswith('play_'): queue.put(value) - + elif value.startswith('exec_'): + t = Thread(target=self.__execute, args=(value[5:], )) + t.start() elif value == 'SUSPEND_LIBRARY_THREAD-True': state.SUSPEND_LIBRARY_THREAD = True elif value == 'SUSPEND_LIBRARY_THREAD-False': diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 879a4d72..c8a5b4ca 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -31,7 +31,7 @@ except IndexError: ############################################################################### -def chooseServer(): +def choose_server(): """ Lets user choose from list of PMS """