Ejemplo n.º 1
0
 def testNotifyOnCreateFile(self):
     changedFiles = []
     dw = DirectoryWatcher(self.tempdir, lambda f: changedFiles.append(f), CreateFile=True)
     f = open(join(self.tempdir, 'createtest'), 'w')
     f.write("test")
     f.close()
     dw()
     self.assertEquals(1, len(changedFiles))
     self.assertEquals('createtest', changedFiles[0].name)
Ejemplo n.º 2
0
 def _initialize(self, reactor, watch):
     self._loadAllTemplates()
     if watch:
         for directory in self._directories:
             directoryWatcher = DirectoryWatcher(directory,
                                                 self._notifyHandler,
                                                 CreateFile=True,
                                                 ModifyFile=True,
                                                 MoveInFile=True)
             reactor.addReader(directoryWatcher, directoryWatcher)
Ejemplo n.º 3
0
    def testNotifyOnMoveInFile(self):
        f = open('/tmp/tempfile', 'w')
        f.write("test")
        f.close()
        changedFiles = []
        dw = DirectoryWatcher(self.tempdir, lambda f: changedFiles.append(f), MoveInFile=True)

        rename('/tmp/tempfile', join(self.tempdir, 'moveintest'))
        dw()
        self.assertEquals(1, len(changedFiles))
        self.assertEquals('moveintest', changedFiles[0].name)
Ejemplo n.º 4
0
    def testNotifyOnCreateAndModifyFile(self):
        changedFiles = []
        dw = DirectoryWatcher(self.tempdir, lambda f: changedFiles.append(f), CreateFile=True, ModifyFile=True)
        open(join(self.tempdir, 'createmodifytest'), 'w').close()
        
        dw()
        self.assertEquals(1, len(changedFiles))
        self.assertEquals('createmodifytest', changedFiles[0].name)

        open(join(self.tempdir, 'createmodifytest'), 'a').write('test')
        dw()
        self.assertEquals(2, len(changedFiles))
        self.assertEquals('createmodifytest', changedFiles[1].name)
Ejemplo n.º 5
0
    def testNotifyOnModifyFile(self):
        changedFiles = []
        f = open(join(self.tempdir, 'modifytest'), 'w')
        f.write("line 1")
        f.close()

        dw = DirectoryWatcher(self.tempdir, lambda f: changedFiles.append(f), ModifyFile=True)
        f = open(join(self.tempdir, 'modifytest'), 'a')
        f.write("line 2")
        f.close()

        dw()
        self.assertEquals(1, len(changedFiles))
        self.assertEquals('modifytest', changedFiles[0].name)
Ejemplo n.º 6
0
    def __init__(self, reactor=None, inboxDirectory='', doneDirectory=''):
        Observable.__init__(self)

        if not isdir(inboxDirectory):
            raise InboxException("directory %s does not exist" %
                                 inboxDirectory)

        if not isdir(doneDirectory):
            raise InboxException("directory %s does not exist" % doneDirectory)

        self._inboxDirectory = inboxDirectory
        self._doneDirectory = doneDirectory
        self._watcher = DirectoryWatcher(self._inboxDirectory,
                                         self._processEvent,
                                         MoveInFile=True)
        reactor.addReader(self._watcher, self._watcher)
Ejemplo n.º 7
0
    def __init__(self, mapping, reactor=None, **kwargs):
        Observable.__init__(self, **kwargs)
        self._mapping = {}
        self._watchers = {}
        self._reactor = reactor
        self._magic = Magic(mime=True)
        for shortname, filename in mapping.items():
            if not isfile(filename):
                print(f"file {filename} for {shortname} does not exist.")
                del self._mapping[shortname]
            else:
                if not self._reactor is None:
                    basedir = dirname(filename)
                    if not basedir in self._watchers:
                        self._watchers[basedir] = DirectoryWatcher(
                            basedir,
                            self._update,
                            ModifyFile=True,
                            MoveInFile=True)
                self._updateFile(shortname, filename)

        if not self._reactor is None:
            for each in self._watchers.values():
                self._reactor.addReader(each, each)
Ejemplo n.º 8
0
 def testNoMask(self):
     try:
         dw = DirectoryWatcher(self.tempdir, lambda f: None)
         self.fail()
     except DirectoryWatcherException, e:
         self.assertEquals('No mask provided.', str(e))