def setup(self):
     self.folder = translatepath('special://addon/resources/lib/tests')
     setPathRW(self.folder)
     watchdogSettings = [{'folder':self.folder, 'patterns':'*', 'ignore_patterns':'', 'ignore_directories':True,
                         'recursive':False, 'key':'E1'}]
     self.dispatcher = Dispatcher()
     self.subscriber = testSubscriber()
     self.topic = Topic('onFileSystemChange','E1')
     self.subscriber.addTopic(self.topic)
     self.dispatcher.addSubscriber(self.subscriber)
     settings = Settings()
     flexmock(settings, getWatchdogSettings=watchdogSettings)
     self.publisher = WatchdogPublisher(self.dispatcher, settings)
     self.dispatcher.start()
 def setup(self):
     self.folder = translatepath('special://addon/resources/lib/tests')
     setPathRW(self.folder)
     watchdogSettings = [{
         'folder': self.folder,
         'patterns': '*',
         'ignore_patterns': '',
         'ignore_directories': True,
         'recursive': False,
         'key': 'E1'
     }]
     self.dispatcher = Dispatcher()
     self.subscriber = testSubscriber()
     self.topic = Topic('onFileSystemChange', 'E1')
     self.subscriber.addTopic(self.topic)
     self.dispatcher.addSubscriber(self.subscriber)
     settings = Settings()
     flexmock(settings, getWatchdogSettings=watchdogSettings)
     self.publisher = WatchdogPublisher(self.dispatcher, settings)
     self.dispatcher.start()
 def setup(self):
     self.folder = translatepath("special://addon/resources/lib/tests")
     setPathRW(self.folder)
     watchdogSettings = [
         {
             "folder": self.folder,
             "patterns": "*",
             "ignore_patterns": "",
             "ignore_directories": True,
             "recursive": False,
             "key": "E1",
         }
     ]
     self.dispatcher = Dispatcher()
     self.subscriber = MockSubscriber()
     self.topic = Topic("onFileSystemChange", "E1")
     self.subscriber.addTopic(self.topic)
     self.dispatcher.addSubscriber(self.subscriber)
     settings = Settings()
     flexmock(settings, getWatchdogSettings=watchdogSettings)
     self.publisher = WatchdogPublisher(self.dispatcher, settings)
     self.dispatcher.start()
def createUserTasks():
    paths = [translatepath('special://addondata')]
    try:
        setPathRW(paths[0])
    except OSError:
        pass
    paths.append(os.path.join(paths[0], 'lib'))
    paths.append(os.path.join(paths[1], 'usertasks'))
    for path in paths:
        if not os.path.isdir(path):
            try:
                os.mkdir(path)
                setPathExecuteRW(path)
            except OSError:
                pass
    for path in paths[1:]:
        fn = os.path.join(path, '__init__.py')
        if not os.path.isfile(fn):
            try:
                with open(fn, mode='w') as f:
                    f.writelines('')
                setPathExecuteRW(fn)
            except (OSError, IOError):
                pass
def createUserTasks():
    paths = [translatepath('special://addondata')]
    try:
        setPathRW(paths[0])
    except OSError:
        pass
    paths.append(os.path.join(paths[0], 'lib'))
    paths.append(os.path.join(paths[1], 'usertasks'))
    for path in paths:
        if not os.path.isdir(path):
            try:
                os.mkdir(path)
                setPathExecuteRW(path)
            except OSError:
                pass
    for path in paths[1:]:
        fn = os.path.join(path, '__init__.py')
        if not os.path.isfile(fn):
            try:
                with open(fn, mode='w') as f:
                    f.writelines('')
                setPathExecuteRW(fn)
            except (OSError, IOError):
                pass
示例#6
0
 def getPicklePath():
     path = translatepath('special://addondata/watchdog.pkl')
     setPathRW(os.path.split(path)[0])
     return path
class testLog(object):
    path = translatepath('special://addondata')
    if not os.path.exists(path):
        os.mkdir(path)
    setPathRW(path)
    fn = translatepath('special://addondata/kodi.log')

    def __init__(self):
        self.publisher = None
        self.dispatcher = None
        self.subscriber = None
        self.globalidletime = None
        self.starttime = None
        self.topics = None

    @staticmethod
    def logSimulate():
        import random, string
        randomstring = ''.join(
            random.choice(string.lowercase) for i in range(30)) + '\n'
        targetstring = '%s%s%s' % (randomstring[:12], 'kodi_callbacks',
                                   randomstring[20:])
        for i in xrange(0, 10):
            with open(testLog.fn, 'a') as f:
                if i == 5:
                    f.writelines(targetstring)
                else:
                    f.writelines(randomstring)
            time.sleep(0.25)

    def setup(self):
        flexmock(log, logfn=testLog.fn)
        flexmock(log.xbmc, log=printlog)
        flexmock(log.xbmc, sleep=sleep)
        self.dispatcher = Dispatcher()
        self.subscriber = testSubscriber()

    def teardown(self):
        self.publisher.abort()
        self.dispatcher.abort()
        del self.publisher
        del self.dispatcher

    def testLogSimple(self):
        self.topics = [Topic('onLogSimple', 'E1')]
        xsettings = [{
            'matchIf': 'kodi_callbacks',
            'rejectIf': '',
            'eventId': 'E1'
        }]
        settings = Settings()
        flexmock(settings, getLogSimples=xsettings)
        flexmock(settings, general={'LogFreq': 100})
        self.publisher = LogPublisher(self.dispatcher, settings)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        finally:
            with open(testLog.fn, 'w') as f:
                f.writelines('')
        self.subscriber.addTopic(self.topics[0])
        self.dispatcher.addSubscriber(self.subscriber)
        self.dispatcher.start()
        self.publisher.start()
        t = threading.Thread(target=testLog.logSimulate)
        t.start()
        t.join()
        self.publisher.abort()
        self.dispatcher.abort()
        time.sleep(2)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        messages = self.subscriber.retrieveMessages()
        msgtopics = [msg.topic for msg in messages]
        for topic in self.topics:
            assert topic in msgtopics

    def testLogRegex(self):
        self.topics = [Topic('onLogRegex', 'E1')]
        xsettings = [{
            'matchIf': 'kodi_callbacks',
            'rejectIf': '',
            'eventId': 'E1'
        }]
        settings = Settings()
        flexmock(settings, getLogRegexes=xsettings)
        flexmock(settings, general={'LogFreq': 100})
        self.publisher = LogPublisher(self.dispatcher, settings)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        finally:
            with open(testLog.fn, 'w') as f:
                f.writelines('')
        self.subscriber.addTopic(self.topics[0])
        self.dispatcher.addSubscriber(self.subscriber)
        self.dispatcher.start()
        self.publisher.start()
        t = threading.Thread(target=testLog.logSimulate)
        t.start()
        t.join()
        self.publisher.abort()
        self.dispatcher.abort()
        time.sleep(2)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        messages = self.subscriber.retrieveMessages()
        msgtopics = [msg.topic for msg in messages]
        for topic in self.topics:
            assert topic in msgtopics