def start(): global log settings = Settings() settings.getSettings() kl = KodiLogger() if settings.general['elevate_loglevel'] is True: kl.setLogLevel(xbmc.LOGNOTICE) else: kl.setLogLevel(xbmc.LOGDEBUG) log = kl.log log(msg=_('Settings read')) Cache.dispatcher = PubSub_Threaded.Dispatcher(interval=settings.general['TaskFreq'], sleepfxn=xbmc.sleep) log(msg=_('Dispatcher initialized')) subscriberfactory = SubscriberFactory(settings, kl) subscribers = subscriberfactory.createSubscribers() for subscriber in subscribers: Cache.dispatcher.addSubscriber(subscriber) publisherfactory = PublisherFactory(settings, subscriberfactory.topics, Cache.dispatcher, kl, debug) publisherfactory.createPublishers() Cache.publishers = publisherfactory.ipublishers Cache.dispatcher.start() log(msg=_('Dispatcher started')) for p in Cache.publishers: try: p.start() except threading.ThreadError: raise log(msg=_('Publisher(s) started'))
def logSettings(self): import pprint settingspp = {'Tasks': self.tasks, 'Events': self.events, 'General': self.general} pp = pprint.PrettyPrinter(indent=2) msg = pp.pformat(settingspp) kl = KodiLogger() kl.log(msg=msg)
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 logSettings(self): import pprint settingspp = { 'Tasks': self.tasks, 'Events': self.events, 'General': self.general } pp = pprint.PrettyPrinter(indent=2) msg = pp.pformat(settingspp) kl = KodiLogger() kl.log(msg=msg)
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 start(): global log settings = Settings() settings.getSettings() kl = KodiLogger() if settings.general['elevate_loglevel'] is True: kl.setLogLevel(xbmc.LOGINFO) else: kl.setLogLevel(xbmc.LOGDEBUG) log = kl.log log(msg=_('Settings read')) Cache.dispatcher = PubSub_Threaded.Dispatcher( interval=settings.general['TaskFreq'], sleepfxn=xbmc.sleep) log(msg=_('Dispatcher initialized')) subscriberfactory = SubscriberFactory(settings, kl) subscribers = subscriberfactory.createSubscribers() for subscriber in subscribers: Cache.dispatcher.addSubscriber(subscriber) publisherfactory = PublisherFactory(settings, subscriberfactory.topics, Cache.dispatcher, kl, debug) publisherfactory.createPublishers() Cache.publishers = publisherfactory.ipublishers Cache.dispatcher.start() log(msg=_('Dispatcher started')) for p in Cache.publishers: try: p.start() except threading.ThreadError: raise log(msg=_('Publisher(s) started'))
# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from resources.lib.pubsub import TaskReturn from resources.lib.utils.poutil import KodiPo from resources.lib.kodilogging import KodiLogger kl = KodiLogger() log = kl.log kodipo = KodiPo() _ = kodipo.getLocalizedString def testMsg(taskManager, taskSettings, kwargs): msg = [ _('Testing for task type: %s') % taskSettings['type'], _('Settings: %s') % str(taskManager.taskKwargs), _('Runtime kwargs: %s') % str(kwargs) ] return msg class TestHandler(object):
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # import os import codecs import fnmatch import re import operator import xbmcaddon import threading import copy from resources.lib.utils.kodipathtools import translatepath from resources.lib.kodilogging import KodiLogger klogger = KodiLogger() log = klogger.log try: addonid = xbmcaddon.Addon().getAddonInfo('id') except RuntimeError: addonid = 'script.service.kodi.callbacks' if addonid == '': addonid = 'script.service.kodi.callbacks' class KodiPo(object): _instance = None _lock = threading.Lock()
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') if __name__ == '__main__': if testTasks: KodiLogger.setLogLevel(KodiLogger.LOGINFO) startdebugger() from resources.lib.tests.testTasks import testTasks tt = testTasks() tt.runTests() else: if branch != 'master': try: from resources.lib.utils.githubtools import processargs except ImportError: pass else: processargs(sys.argv) main()
msgList = testlogger.retrieveLogAsList() import resources.lib.dialogtb as dialogtb dialogtb.show_textbox('Error', msgList) xbmc.sleep(2000) if __name__ == '__main__': if len(sys.argv) > 1: if testdebug is True and debug is False: startdebugger() if sys.argv[1] == 'regen': from resources.lib.utils.xml_gen import generate_settingsxml generate_settingsxml() elif sys.argv[1] == 'test': KodiLogger.setLogLevel(KodiLogger.LOGNOTICE) from resources.lib.tests.testTasks import testTasks tt = testTasks() tt.runTests() dialog = xbmcgui.Dialog() msg = _('Native Task Testing Complete - see log for results') dialog.notification('Kodi Callbacks', msg, xbmcgui.NOTIFICATION_INFO, 5000) elif sys.argv[1] == 'updatefromzip': from resources.lib.utils.kodipathtools import translatepath KodiLogger.setLogLevel(KodiLogger.LOGNOTICE) dialog = xbmcgui.Dialog() zipfn = dialog.browse(1, _('Locate zip file'), 'files', '.zip', False, False, translatepath('~')) if zipfn != translatepath('~'): if os.path.isfile(zipfn):
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') if __name__ == '__main__': if testTasks: KodiLogger.setLogLevel(KodiLogger.LOGNOTICE) startdebugger() from resources.lib.tests.testTasks import testTasks tt = testTasks() tt.runTests() else: if branch != 'master': try: from resources.lib.utils.githubtools import processargs except ImportError: pass else: processargs(sys.argv) main()