Esempio n. 1
0
    def add(self, path, mask):
        '''Add or modify a watch.

        Return the watch descriptor added or modified.'''

        path = os.path.normpath(path)
        wd = inotify.add_watch(self.fd, path, mask)
        self._paths[path] = wd, mask
        self._wds[wd] = path, mask
        return wd
Esempio n. 2
0
    def add(self, path, mask):
        '''Add or modify a watch.

        Return the watch descriptor added or modified.'''

        path = os.path.normpath(path)
        wd = inotify.add_watch(self.fd, path, mask)
        self._paths[path] = wd, mask
        self._wds[wd] = path, mask
        return wd
Esempio n. 3
0
    def add(self, path, mask):
        '''Add or modify a watch.

        Return the watch descriptor added or modified.'''

        path = os.path.normpath(path)
        wd = inotify.add_watch(self.fd, path.encode('utf-8'), mask)

        if (wd >= 0):
            self._paths[path] = wd, mask
            self._wds[wd] = path, mask
            return wd
        else:
            return -1
Esempio n. 4
0
    def watch(self, path, mask = None):
        """
        Adds a watch to the given path.  The default mask is anything that
        causes a change (new file, deleted file, modified file, or attribute
        change on the file).  This function returns a Signal that the caller
        can then connect to.  Any time there is a notification, the signal
        will get emitted.  Callbacks connected to the signal must accept 2
        arguments: notify mask and filename.
        """
        path = os.path.realpath(path)
        if path in self._watches_by_path:
            return self._watches_by_path[path][0]

        if mask == None:
            mask = INotify.WATCH_MASK

        wd = _inotify.add_watch(self._fd, path, mask)
        if wd < 0:
            raise IOError, "Failed to add watch on '%s'" % path

        signal = kaa.Signal()
        self._watches[wd] = [signal, path]
        self._watches_by_path[path] = [signal, wd]
        return signal