Exemplo n.º 1
0
    def dispatch(self, event):
        """Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        """
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if any(r.match(p) for r in self.ignore_regexes for p in paths):
            return

        if any(r.match(p) for r in self.regexes for p in paths):
            self.on_any_event(event)
            _method_map = {
                EVENT_TYPE_MODIFIED: self.on_modified,
                EVENT_TYPE_ATTR_MODIFIED: self.on_attr_modified,
                EVENT_TYPE_MOVED: self.on_moved,
                EVENT_TYPE_CREATED: self.on_created,
                EVENT_TYPE_DELETED: self.on_deleted,
            }
            event_type = event.event_type
            _method_map[event_type](event)
Exemplo n.º 2
0
    def dispatch(self, event):
        """Override superclass method.

        Append trailing slash to event src_path if it is a directory event and
        its dest_path if exists before matching using fnmatch.

        Args:
            event: The event object to dispatch.
        """
        if event.is_directory and self._ignore_directories:
            return

        paths = []
        if hasattr(event, 'dest_path'):
            dest_path = self._slash(event, event.dest_path)
            paths.append(unicode_paths.decode(dest_path))
        if event.src_path:
            src_path = self._slash(event, event.src_path)
            paths.append(unicode_paths.decode(src_path))

        if match_any_paths(paths,
                           included_patterns=self._patterns,
                           excluded_patterns=self._ignore_patterns,
                           case_sensitive=self.case_sensitive):
            self.on_any_event(event)
            method_map = {
                EVENT_TYPE_CREATED: self.on_created,
                EVENT_TYPE_MODIFIED: self.on_modified,
                EVENT_TYPE_MOVED: self.on_moved,
                EVENT_TYPE_DELETED: self.on_deleted,
            }
            event_type = event.event_type
            method_map[event_type](event)
Exemplo n.º 3
0
    def dispatch(self, event):
        """Override superclass method.

        Append trailing slash to event src_path if it is a directory event and
        its dest_path if exists before matching using fnmatch.

        Args:
            event: The event object to dispatch.
        """
        if event.is_directory and self._ignore_directories:
            return

        paths = []
        if hasattr(event, 'dest_path'):
            dest_path = self._slash(event, event.dest_path)
            paths.append(unicode_paths.decode(dest_path))
        if event.src_path:
            src_path = self._slash(event, event.src_path)
            paths.append(unicode_paths.decode(src_path))

        if match_any_paths(paths,
                           included_patterns=self._patterns,
                           excluded_patterns=self._ignore_patterns,
                           case_sensitive=self.case_sensitive):
            self.on_any_event(event)
            method_map = {
                EVENT_TYPE_CREATED: self.on_created,
                EVENT_TYPE_MODIFIED: self.on_modified,
                EVENT_TYPE_MOVED: self.on_moved,
                EVENT_TYPE_DELETED: self.on_deleted,
            }
            event_type = event.event_type
            method_map[event_type](event)
Exemplo n.º 4
0
    def dispatch(self, event):
        """Dispatch an event after filtering. We handle
        creation and move events only.
        
        :param event: watchdog event.

        :returns: None
        """
        if event.event_type not in (EVENT_TYPE_CREATED, EVENT_TYPE_MOVED):
            return
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if any(r.match(p) for r in self.ignore_regexes for p in paths):
            return

        if any(r.match(p) for r in self.regexes for p in paths):
            self._loop.call_soon_threadsafe(asyncio. async,
                                            self._process_file(event))
Exemplo n.º 5
0
    def dispatch(self, event):
        """Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        """
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if any(r.match(p) for r in self.ignore_regexes for p in paths):
            return

        if any(r.match(p) for r in self.regexes for p in paths):
            self.on_any_event(event)
            _method_map = {
                EVENT_TYPE_MODIFIED: self.on_modified,
                EVENT_TYPE_MOVED: self.on_moved,
                EVENT_TYPE_CREATED: self.on_created,
                EVENT_TYPE_DELETED: self.on_deleted,
            }
            event_type = event.event_type
            _method_map[event_type](event)
Exemplo n.º 6
0
    def dispatch(self, event):
        """Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        """
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if match_any_paths(paths,
                           included_patterns=self.patterns,
                           excluded_patterns=self.ignore_patterns,
                           case_sensitive=self.case_sensitive):
            self.on_any_event(event)
            _method_map = {
                EVENT_TYPE_MODIFIED: self.on_modified,
                EVENT_TYPE_MOVED: self.on_moved,
                EVENT_TYPE_CREATED: self.on_created,
                EVENT_TYPE_DELETED: self.on_deleted,
            }
            event_type = event.event_type
            _method_map[event_type](event)
Exemplo n.º 7
0
    def dispatch(self, event):
        # There isn't any point in triggering builds on new directory creation.
        # It's the creation or modification of files that indicate something
        # meaningful enough changed for a build.
        if event.is_directory:
            return

        # Collect paths of interest from the event.
        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))
        for path in paths:
            _LOG.debug('File event: %s', path)

        # Check for matching paths among the one or two in the event.
        matching_path = None
        for path in paths:
            if self.path_matches(path):
                _LOG.debug('Detected event: %s', path)
                matching_path = path
                break

        if matching_path:
            self.handle_matched_event(matching_path)
Exemplo n.º 8
0
    def dispatch(self, event):
        """Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        """
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if match_any_paths(paths,
                           included_patterns=self.patterns,
                           excluded_patterns=self.ignore_patterns,
                           case_sensitive=self.case_sensitive):
            self.on_any_event(event)
            _method_map = {
                EVENT_TYPE_MODIFIED: self.on_modified,
                EVENT_TYPE_ATTR_MODIFIED: self.on_attr_modified,
                EVENT_TYPE_MOVED: self.on_moved,
                EVENT_TYPE_CREATED: self.on_created,
                EVENT_TYPE_DELETED: self.on_deleted,
            }
            event_type = event.event_type
            _method_map[event_type](event)
Exemplo n.º 9
0
 def dispatch(self, event):
     if event.src_path and self.spec.match_file(
             unicode_paths.decode(event.src_path)):
         if self.debugging:
             print(f"Ignoring source change on {event.src_path}")
         return
     if has_attribute(event, "dest_path") and self.spec.match_file(
             unicode_paths.decode(event.dest_path)):
         if self.debugging:
             print(f"Ignoring destination change on {event.dest_path}")
         return
     super().dispatch(event)
Exemplo n.º 10
0
    def dispatch(self, event):
        """Dispatches events to the appropriate methods."""
        current_time = datetime.now()
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, "dest_path"):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if match_any_paths(
                paths,
                included_patterns=self.patterns,
                excluded_patterns=self.ignore_patterns,
                case_sensitive=self.case_sensitive,
        ):
            _method_map = {
                EVENT_TYPE_MODIFIED: self.on_modified,
                EVENT_TYPE_MOVED: self.on_moved,
                EVENT_TYPE_CREATED: self.on_created,
                EVENT_TYPE_DELETED: self.on_deleted,
            }
            event_type = event.event_type
            event_tuple = (event.src_path, event_type)

            if not self._coalesce:
                self.on_any_event(*self._args, event=event, **self._kwargs)
                _method_map[event_type](*self._args,
                                        event=event,
                                        **self._kwargs)

            elif event_tuple in self._src_path_timing:
                if (current_time - self._src_path_timing[event_tuple] >
                        self._min_delta_time):
                    # Update the time
                    self._src_path_timing[event_tuple] = datetime.now()

                    self.on_any_event(*self._args, event=event, **self._kwargs)
                    _method_map[event_type](*self._args,
                                            event=event,
                                            **self._kwargs)
            else:
                self._src_path_timing[event_tuple] = datetime.now()

                self.on_any_event(*self._args, event=event, **self._kwargs)
                _method_map[event_type](*self._args,
                                        event=event,
                                        **self._kwargs)
Exemplo n.º 11
0
def get_file_event_paths(events):
    for event in events:
        for key in ('dest_path', 'src_path'):
            if has_attribute(event, key):
                path = unicode_paths.decode(getattr(event, key))
                if not (path.startswith('.autocheck.') or os.path.isdir(path)):
                    yield os.path.relpath(path)
Exemplo n.º 12
0
 def dispatch(self, event):
     if self.ignore_directories and event.is_directory:
         return
     paths = []
     if has_attribute(event, 'dest_path'):
         paths.append(unicode_paths.decode(event.dest_path))
     if event.src_path:
         paths.append(unicode_paths.decode(event.src_path))
     if match_any_paths(paths, included_patterns=self.patterns, excluded_patterns=self.ignore_patterns, case_sensitive=self.case_sensitive):
         self.on_any_event(event)
         _method_map = {EVENT_TYPE_MODIFIED: self.on_modified,
          EVENT_TYPE_MOVED: self.on_moved,
          EVENT_TYPE_CREATED: self.on_created,
          EVENT_TYPE_DELETED: self.on_deleted}
         event_type = event.event_type
         _method_map[event_type](event)
Exemplo n.º 13
0
def get_file_event_paths(events):
    for event in events:
        for key in ('dest_path', 'src_path'):
            if has_attribute(event, key):
                path = unicode_paths.decode(getattr(event, key))
                if not (path.startswith('.autocheck.') or os.path.isdir(path)):
                    yield os.path.relpath(path)
Exemplo n.º 14
0
    def on_moved(self, event):
        """Translate filesystem move events. DO NOT OVERRIDE."""
        src_path = unicode_paths.decode(event.src_path)
        dest_path = unicode_paths.decode(event.dest_path)

        src_match = any(r.match(src_path) for r in self.regexes)
        dest_match = any(r.match(dest_path) for r in self.regexes)

        if src_match and dest_match:
            self.on_drf_moved(event)
        elif src_match:
            new_event = FileDeletedEvent(event.src_path)
            self.on_deleted(new_event)
        else:
            new_event = FileCreatedEvent(event.dest_path)
            self.on_created(new_event)
Exemplo n.º 15
0
 def dispatch(self, event):
     if self.ignore_directories and event.is_directory:
         return
     paths = []
     if has_attribute(event, 'dest_path'):
         paths.append(unicode_paths.decode(event.dest_path))
     if event.src_path:
         paths.append(unicode_paths.decode(event.src_path))
     if any((r.match(p) for r in self.ignore_regexes for p in paths)):
         return
     if any((r.match(p) for r in self.regexes for p in paths)):
         self.on_any_event(event)
         _method_map = {EVENT_TYPE_MODIFIED: self.on_modified,
          EVENT_TYPE_MOVED: self.on_moved,
          EVENT_TYPE_CREATED: self.on_created,
          EVENT_TYPE_DELETED: self.on_deleted}
         event_type = event.event_type
         _method_map[event_type](event)
Exemplo n.º 16
0
 def dispatch(self, event):
     if self.ignore_directories and event.is_directory:
         return
     paths = []
     if has_attribute(event, 'dest_path'):
         paths.append(unicode_paths.decode(event.dest_path))
     if event.src_path:
         paths.append(unicode_paths.decode(event.src_path))
     if any((r.match(p) for r in self.ignore_regexes for p in paths)):
         return
     if any((r.match(p) for r in self.regexes for p in paths)):
         self.on_any_event(event)
         _method_map = {
             EVENT_TYPE_MODIFIED: self.on_modified,
             EVENT_TYPE_MOVED: self.on_moved,
             EVENT_TYPE_CREATED: self.on_created,
             EVENT_TYPE_DELETED: self.on_deleted
         }
         event_type = event.event_type
         _method_map[event_type](event)
Exemplo n.º 17
0
    def dispatch(self, event):
        """Only dispatch if the event does not correspond to an ignored file.
        Args:
            event (watchdog.events.FileSystemEvent)
        """
        if event.is_directory:
            return
        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(os.path.realpath(
                unicode_paths.decode(event.dest_path)))
        if event.src_path:
            paths.append(os.path.realpath(
                unicode_paths.decode(event.src_path)))
        paths = [p for p in paths
                 if not p.startswith(os.path.realpath(self.vcs.repository_dir()))
                 and not self.vcs.path_is_ignored(p)]

        if len(paths) > 0:
            super(VcsEventHandler, self).dispatch(event)
Exemplo n.º 18
0
 def dispatch(self, event):
     if self.ignore_directories and event.is_directory:
         return
     paths = []
     if has_attribute(event, 'dest_path'):
         paths.append(unicode_paths.decode(event.dest_path))
     if event.src_path:
         paths.append(unicode_paths.decode(event.src_path))
     if match_any_paths(paths,
                        included_patterns=self.patterns,
                        excluded_patterns=self.ignore_patterns,
                        case_sensitive=self.case_sensitive):
         self.on_any_event(event)
         _method_map = {
             EVENT_TYPE_MODIFIED: self.on_modified,
             EVENT_TYPE_MOVED: self.on_moved,
             EVENT_TYPE_CREATED: self.on_created,
             EVENT_TYPE_DELETED: self.on_deleted
         }
         event_type = event.event_type
         _method_map[event_type](event)
Exemplo n.º 19
0
    def dispatch(self, event):
        """Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        """
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if match_any_paths(paths,
                           included_patterns=self.patterns,
                           excluded_patterns=self.ignore_patterns,
                           case_sensitive=self.case_sensitive):
            super(PatternMatchingEventHandler, self).dispatch(event)
Exemplo n.º 20
0
    def dispatch(self, event):
        """Dispatches events to the appropriate methods.

        :param event:
            The event object representing the file system event.
        :type event:
            :class:`FileSystemEvent`
        """
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if any(r.match(p) for r in self.ignore_regexes for p in paths):
            return

        if any(r.match(p) for r in self.regexes for p in paths):
            super(RegexMatchingEventHandler, self).dispatch(event)
Exemplo n.º 21
0
    def dispatch(self, event):
        """Dispatch an event after filtering. We handle
        creation and move events only.
        
        :param event: watchdog event.

        :returns: None
        """
        if event.event_type not in (EVENT_TYPE_CREATED, EVENT_TYPE_MOVED):
            return
        if self.ignore_directories and event.is_directory:
            return

        paths = []
        if has_attribute(event, 'dest_path'):
            paths.append(unicode_paths.decode(event.dest_path))
        if event.src_path:
            paths.append(unicode_paths.decode(event.src_path))

        if any(r.match(p) for r in self.ignore_regexes for p in paths):
            return

        if any(r.match(p) for r in self.regexes for p in paths):
            self._loop.call_soon_threadsafe(asyncio.async, self._process_file(event))
Exemplo n.º 22
0
    def on_created(self, event):
        try:
            if event.is_directory:
                # Create directory
                print "Created directory: ", event.src_path
                self._create_dir(event.src_path)
            else:
                paths = []
                if event.src_path:
                    paths.append(unicode_paths.decode(event.src_path))

                if match_any_paths(paths,
                                   included_patterns=self.patterns,
                                   case_sensitive=False):

                    print "Created file: ", event.src_path
                    self._create_file(event.src_path)
        except Exception as e:
            print "Unable to upload change: ", e
Exemplo n.º 23
0
 def __repr__(self):
     mask_string = self._get_mask_string(self.mask)
     s = '<%s: src_path=%r, wd=%d, mask=%s, cookie=%d, name=%s>'
     return s % (type(self).__name__, self.src_path, self.wd, mask_string,
                 self.cookie, decode(self.name))
Exemplo n.º 24
0
 def _decode_path(self, path):
     """ Decode path only if unicode string was passed to this emitter. """
     if isinstance(self.watch.path, bytes):
         return path
     return unicode_paths.decode(path)
Exemplo n.º 25
0
 def __repr__(self):
     mask_string = self._get_mask_string(self.mask)
     s = '<%s: src_path=%r, wd=%d, mask=%s, cookie=%d, name=%s>'
     return s % (type(self).__name__, self.src_path, self.wd, mask_string,
                 self.cookie, decode(self.name))
Exemplo n.º 26
0
 def _decode_path(self, path):
     if isinstance(self.watch.path, bytes):
         return path
     return unicode_paths.decode(path)
Exemplo n.º 27
0
 def _decode_path(self, path):
     """ Decode path only if unicode string was passed to this emitter. """
     if isinstance(self.watch.path, bytes):
         return path
     return unicode_paths.decode(path)
Exemplo n.º 28
0
    def dispatch(self, event, match_time=True):
        """Dispatch events to the appropriate methods.

        Parameters
        ----------
        event : FileSystemEvent
            Event object representing the file system event.

        match_time : bool
            If False, do not check the matched file's time against the
            handler's starttime and endtime.

        """
        if self.ignore_directories and event.is_directory:
            return

        src_match = False
        if event.src_path:
            src_path = unicode_paths.decode(event.src_path)
            if not any(r.match(src_path) for r in self.ignore_regexes):
                for r in self.regexes:
                    m = r.match(src_path)
                    if m:
                        src_match = True
                        match = m

        dest_match = False
        if getattr(event, "dest_path", None) is not None:
            dest_path = unicode_paths.decode(event.dest_path)
            if not any(r.match(dest_path) for r in self.ignore_regexes):
                for r in self.regexes:
                    m = r.match(dest_path)
                    if m:
                        dest_match = True
                        match = m

            # change move event to deleted/created if both regexes didn't match
            if src_match and not dest_match:
                event = FileDeletedEvent(event.src_path)
            elif dest_match and not src_match:
                event = FileCreatedEvent(event.dest_path)

        if not src_match and not dest_match:
            return

        # regexes matched, now check the time
        if match_time:
            try:
                secs = int(match.group("secs"))
            except (IndexError, TypeError):
                # no time, don't need to check it
                pass
            else:
                try:
                    msecs = int(match.group("frac"))
                except (IndexError, TypeError):
                    msecs = 0
                time = datetime.timedelta(seconds=secs, milliseconds=msecs)
                if self.starttime is not None and time < self.starttime:
                    return
                elif self.endtime is not None and time > self.endtime:
                    return

        # the event matched, including time if applicable, dispatch
        self.on_any_event(event)
        _method_map = {
            "modified": self.on_modified,
            "moved": self.on_moved,
            "created": self.on_created,
            "deleted": self.on_deleted,
        }
        event_type = event.event_type
        _method_map[event_type](event)
Exemplo n.º 29
0
 def on_modified(self, event):
     if not event.is_directory and unicode_paths.decode(
             event.src_path) == config_abspath:
         get_config()
Exemplo n.º 30
0
 def _decode_path(self, path):
     if isinstance(self.watch.path, bytes):
         return path
     return unicode_paths.decode(path)