How to use the watchdog.events.FileCreatedEvent function in watchdog

To help you get started, we’ve selected a few watchdog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gorakhargosh / watchdog / tests / legacy / test_watchdog_events.py View on Github external
excluded_patterns=ignore_patterns,
                                          case_sensitive=False)
            self.assertTrue(filtered_paths)

        dir_del_event_match = DirDeletedEvent('/path/blah.py')
        dir_del_event_not_match = DirDeletedEvent('/path/foobar')
        dir_del_event_ignored = DirDeletedEvent('/path/foobar.pyc')
        file_del_event_match = FileDeletedEvent('/path/blah.txt')
        file_del_event_not_match = FileDeletedEvent('/path/foobar')
        file_del_event_ignored = FileDeletedEvent('/path/blah.pyc')

        dir_cre_event_match = DirCreatedEvent('/path/blah.py')
        dir_cre_event_not_match = DirCreatedEvent('/path/foobar')
        dir_cre_event_ignored = DirCreatedEvent('/path/foobar.pyc')
        file_cre_event_match = FileCreatedEvent('/path/blah.txt')
        file_cre_event_not_match = FileCreatedEvent('/path/foobar')
        file_cre_event_ignored = FileCreatedEvent('/path/blah.pyc')

        dir_mod_event_match = DirModifiedEvent('/path/blah.py')
        dir_mod_event_not_match = DirModifiedEvent('/path/foobar')
        dir_mod_event_ignored = DirModifiedEvent('/path/foobar.pyc')
        file_mod_event_match = FileModifiedEvent('/path/blah.txt')
        file_mod_event_not_match = FileModifiedEvent('/path/foobar')
        file_mod_event_ignored = FileModifiedEvent('/path/blah.pyc')

        dir_mov_event_match = DirMovedEvent('/path/blah.py', '/path/blah')
        dir_mov_event_not_match = DirMovedEvent('/path/foobar', '/path/blah')
        dir_mov_event_ignored = DirMovedEvent('/path/foobar.pyc', '/path/blah')
        file_mov_event_match = FileMovedEvent('/path/blah.txt', '/path/blah')
        file_mov_event_not_match = FileMovedEvent('/path/foobar', '/path/blah')
        file_mov_event_ignored = FileMovedEvent('/path/blah.pyc', '/path/blah')
github CenterForOpenScience / osf-sync / tests / sync / test_event_consolidator.py View on Github external
from tests.sync.utils import TestSyncObserver


start_logging()


_map = {
    ('move', True): events.DirMovedEvent,
    ('move', False): events.FileMovedEvent,
    ('modify', True): events.DirModifiedEvent,
    ('modify', False): events.FileModifiedEvent,
    ('delete', True): events.DirDeletedEvent,
    ('delete', False): events.FileDeletedEvent,
    ('create', True): events.DirCreatedEvent,
    ('create', False): events.FileCreatedEvent,
}


def Event(type_, *src, sha=None):
    assert len(src) < 3
    if len(src) > 1:
        assert src[0].endswith('/') == src[1].endswith('/')
    event = _map[(type_, src[0].endswith('/'))](*(x.rstrip('/').replace('/', os.path.sep) for x in src))
    event.sha256 = sha
    return event


CASES = [{
    'input': [Event('modify', '/Foo/bar/')],
    'output': []
}, {
github Komodo / KomodoEdit / src / filesystem / watchdogFileNotifications.py View on Github external
# watch_type - Type of watch to perform (used in addObserver)
WATCH_FILE = 0
WATCH_DIR = 1
WATCH_DIR_RECURSIVE = 2

log = logging.getLogger("watchdogFileNotifications")
#log.setLevel(logging.DEBUG)

class FileSystemPatternEventHandler(watchdog.events.PatternMatchingEventHandler):

    _event_map = {
        watchdog.events.DirCreatedEvent: FS_DIR_CREATED,
        watchdog.events.DirDeletedEvent: FS_DIR_DELETED,
        watchdog.events.DirModifiedEvent: FS_DIR_MODIFIED,
        watchdog.events.FileCreatedEvent: FS_FILE_CREATED,
        watchdog.events.FileDeletedEvent: FS_FILE_DELETED,
        watchdog.events.FileModifiedEvent: FS_FILE_MODIFIED,
    }

    def __init__(self, observer_monitor, flags, patterns=None):
        super(FileSystemPatternEventHandler, self).__init__(patterns=patterns)
        self.observer_monitor = observer_monitor
        self.flags = flags
        self._lock = threading.Lock()

    def has_flags(self, flags):
        return self.flags & flags

    def notify_observer_monitor(self, path, flags):
        with self._lock:
            self.observer_monitor.notifyChanges({path: flags})
github piejanssens / premiumizer / premiumizer / premiumizer.py View on Github external
def walk_watchdir():
    global watchdog_handler
    logger.debug('def walk_watchdir started')
    for dirpath, dirs, files in os.walk(cfg.watchdir_location):
        for file in files:
            filepath = os.path.join(dirpath, file)
            watchdog_handler.on_created(events.FileCreatedEvent(filepath))
    if cfg.watchdir_walk_enabled:
        interval = cfg.watchdir_walk_interval
        scheduler.scheduler.reschedule_job('walk_watchdir', trigger='interval', seconds=interval)
github gorakhargosh / watchdog / watchdog / observers / kqueue_observer.py View on Github external
# add a new kevent for the path.
                    kev, fd = create_kevent_for_path(path)
                    self._kevent_list.append(kev)
                    watch = _Watch(fd, kev, path, is_directory)
                    self._descriptors.add(fd)
                    self._watch_table[fd] = watch
                    self._watch_table[path] = watch
                except OSError, e:
                    if e.errno == errno.ENOENT:
                        # No such file or directory.
                        # Possibly a temporary file we can ignore.
                        if is_directory:
                            event_created_class = DirCreatedEvent
                            event_deleted_class = DirDeletedEvent
                        else:
                            event_created_class = FileCreatedEvent
                            event_deleted_class = FileDeletedEvent

                        self.event_queue.put(
                            event_created_class(path,
                                                handlers=self.handlers))
                        self.event_queue.put(
                            event_deleted_class(path,
                                                handlers=self.handlers))
github richo / groundstation / groundstation / fs_watcher.py View on Github external
def on_created(self, event):
        if isinstance(event, FileCreatedEvent):
            if not self.is_legit_object(event.src_path):
                return
            sent = 0
            data = event.src_path + chr(0)
            data_len = len(data)
            while sent != data_len:
                sent += os.write(self.pipe, data[sent:])
github Komodo / KomodoEdit / contrib / watchdog / src / watchdog / observers / inotify.py View on Github external
i = 0
            while i + 16 < len(event_buffer):
                wd, mask, cookie, length =\
                struct.unpack_from('iIII', event_buffer, i)
                name = event_buffer[i + 16:i + 16 + length].rstrip('\0')
                i += 16 + length
                yield wd, mask, cookie, name


    ACTION_EVENT_MAP = {
        (True, EVENT_TYPE_MODIFIED): DirModifiedEvent,
        (True, EVENT_TYPE_CREATED): DirCreatedEvent,
        (True, EVENT_TYPE_DELETED): DirDeletedEvent,
        (True, EVENT_TYPE_MOVED): DirMovedEvent,
        (False, EVENT_TYPE_MODIFIED): FileModifiedEvent,
        (False, EVENT_TYPE_CREATED): FileCreatedEvent,
        (False, EVENT_TYPE_DELETED): FileDeletedEvent,
        (False, EVENT_TYPE_MOVED): FileMovedEvent,
    }

    class InotifyEmitter(EventEmitter):
        """
        inotify(7)-based event emitter.

        :param event_queue:
            The event queue to fill with events.
        :param watch:
            A watch object representing the directory to monitor.
        :type watch:
            :class:`watchdog.observers.api.ObservedWatch`
        :param timeout:
            Read events blocking timeout (in seconds).
github snakeleon / YouCompleteMe-x64 / third_party / ycmd / third_party / watchdog_deps / watchdog / src / watchdog / observers / kqueue.py View on Github external
Compares information from two directory snapshots (one taken before
        the rename operation and another taken right after) to determine the
        destination path of the file system object renamed, and yields
        the appropriate events to be queued.
        """
        try:
            f_inode = ref_snapshot.inode(src_path)
        except KeyError:
            # Probably caught a temporary file/directory that was renamed
            # and deleted. Fires a sequence of created and deleted events
            # for the path.
            if is_directory:
                yield DirCreatedEvent(src_path)
                yield DirDeletedEvent(src_path)
            else:
                yield FileCreatedEvent(src_path)
                yield FileDeletedEvent(src_path)
                # We don't process any further and bail out assuming
            # the event represents deletion/creation instead of movement.
            return

        dest_path = new_snapshot.path(f_inode)
        if dest_path is not None:
            dest_path = absolute_path(dest_path)
            if is_directory:
                event = DirMovedEvent(src_path, dest_path)
                yield event
            else:
                yield FileMovedEvent(src_path, dest_path)
            yield self._parent_dir_modified(src_path)
            yield self._parent_dir_modified(dest_path)
            if is_directory:
github tomquirk / FlickrBox / flickrbox.py View on Github external
def on_created(self, event):
        if not isinstance(event, watchdog.events.FileCreatedEvent):
            return

        params = self.parse_filepath(event.src_path)
        # ignore any photos that aren't in a sub-directory
        if params["photoset"] == FLICKRBOX:
            return
        self._flickrbox.upload_photo(
            params["photo"], params["ext"], params["photoset"])