def main(): msg = _(u'$$$ [kodi.callbacks] - Staring kodi.callbacks ver: %s (%s:build %s) python: %s').encode('utf-8') % (str(_addonversion_), branch, build, sys.version) xbmc.log(msg=msg, level=xbmc.LOGNOTICE) if branch != 'master': xbmcaddon.Addon().setSetting('installed branch', branch) start() Cache.dispatcher.q_message(PubSub_Threaded.Message(PubSub_Threaded.Topic('onStartup'))) monitor = MainMonitor() log(msg=_('Entering wait loop')) monitor.waitForAbort() # Shutdown tasks Cache.dispatcher.q_message(PubSub_Threaded.Message(PubSub_Threaded.Topic('onShutdown'), pid=os.getpid())) log(msg=_('Shutdown started')) abortall() log(msg='Shutdown complete')
def test(key): global log log = KodiLogger.log import resources.lib.tests.direct_test as direct_test from resources.lib.events import Events import traceback log(msg=_('Running Test for Event: %s') % key) events = Events().AllEvents settings = Settings() settings.getSettings() if settings.general['elevate_loglevel'] is True: KodiLogger.setLogLevel(xbmc.LOGNOTICE) else: KodiLogger.setLogLevel(xbmc.LOGDEBUG) log(msg=_('Settings for test read')) evtsettings = settings.events[key] topic = settings.topicFromSettingsEvent(key) task_key = settings.events[key]['task'] tasksettings = settings.tasks[task_key] testlogger = direct_test.TestLogger() log(msg=_('Creating subscriber for test')) subscriberfactory = SubscriberFactory(settings, testlogger) subscriber = subscriberfactory.createSubscriber(key) if subscriber is not None: log(msg=_('Test subscriber created successfully')) try: kwargs = events[evtsettings['type']]['expArgs'] except KeyError: kwargs = {} testRH = direct_test.TestHandler( direct_test.testMsg(subscriber.taskmanagers[0], tasksettings, kwargs)) subscriber.taskmanagers[0].returnHandler = testRH.testReturnHandler # Run test log(msg=_('Running test')) nMessage = PubSub_Threaded.Message(topic=topic, **kwargs) try: subscriber.notify(nMessage) except Exception: msg = _('Unspecified error during testing') e = sys.exc_info()[0] if hasattr(e, 'message'): msg = str(e.message) msg = msg + '\n' + traceback.format_exc() log(msg=msg) msgList = msg.split('\n') import resources.lib.dialogtb as dialogtb dialogtb.show_textbox('Error', msgList) else: log(msg=_('Test subscriber creation failed due to errors')) msgList = testlogger.retrieveLogAsList() import resources.lib.dialogtb as dialogtb dialogtb.show_textbox('Error', msgList) xbmc.sleep(2000)
def main(): xbmc.log(msg=_('$$$ [kodi.callbacks] Staring kodi.callbacks ver: %s') % str(__version__), level=xbmc.LOGNOTICE) dispatcher, publishers = start() dispatcher.q_message( PubSub_Threaded.Message(PubSub_Threaded.Topic('onStartup'))) monitor = MainMonitor(dispatcher, publishers) log(msg=_('Entering wait loop')) monitor.waitForAbort() # Shutdown tasks dispatcher.q_message( PubSub_Threaded.Message(PubSub_Threaded.Topic('onShutdown'), pid=os.getpid())) xbmc.sleep(500) log(msg=_('Shutdown started')) for p in publishers: try: p.abort() except threading.ThreadError as e: log(msg=_('Error aborting: %s - Error: %s') % (str(p), str(e))) dispatcher.abort() xbmc.sleep(1000) if len(threading.enumerate()) > 1: main_thread = threading.current_thread() log(msg=_('Enumerating threads to kill others than main (%i)') % main_thread.ident) for t in threading.enumerate(): if t is not main_thread: log(msg=_('Attempting to kill thread: %i: %s') % (t.ident, t.name)) xbmc.sleep(25) try: t.abort(0.525) except threading.ThreadError: log(msg=_('Error killing thread')) else: if not t.is_alive(): log(msg=_('Thread killed succesfully')) log(msg='Shutdown complete')