Giter VIP home page Giter VIP logo

trio-inotify's Introduction

trio-inotify

Inotify interface implemented in Trio

Note: This is a PRE-ALPHA project

API is currently subject to change with each release.

Installation

pip install git+https://github.com/ninpo/trio-inotify

Usage:

Simple File Watch for Deletes:

import trio
from trio_inotify.inotify import WatchManager, Watcher, InotifyMasks
wm = WatchManager()
wm.add_watch("/path/to/file/or/dir", watch_mask=InotifyMasks.IN_DELETE)
watcher = Watcher(watch_manager=wm)
events = trio.run(watcher.get_inotify_event)

This will block until there are inotify events, at which point you'll be returned a list of events.

wm.del_watch("/path/to/file/or/dir")

Deletes a watch.

Recursive Directory Watch for File Write Events:

import trio
from trio_inotify.inotify import WatchManager, Watcher, InotifyMasks
wm = WatchManager()
wm.add_watch("/path/to/dir", watch_mask=InotifyMasks.IN_CLOSE_WRITE, recursive=True)
watcher = Watcher(watch_manager=wm)
events = trio.run(watcher.get_inotify_event)

del_watch() on a recursive watch will remove all watches including from any watched sub-dirs. You can also selectively drop sub-dir watches from a recursive watch while keeping watches for other dirs:

Scenario: Watching /home/user/logs

wm.add_watch("/home/user/logs", watch_mask=InotifyMasks.IN_CLOSE_WRITE, recursive=True)
# Watches /home/user/logs, /home/user/logs/subdir1, /home/user/logs/subdir2 etc..
wm.del_watch("/home/user/logs/subdir2")
# Stops watching /home/user/logs/subdir2 and all child 
# directories/files, but still watches /home/user/logs and /home/user/logs/subdir1

Coming Soon:

  • Automatic addition/removal of directory watches when recursively watching a directory on IS_DIR|IN_CREATE/IS_DIR|IN_DELETE events
  • Pass a custom event handler to Watcher

trio-inotify's People

Contributors

dependabot-support avatar ninpo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

pombredanne

trio-inotify's Issues

TypeError: add_watch() got an unexpected keyword argument 'watch_mask'

add_watch() got an unexpected keyword argument 'watch_mask'
but arguments are:
def add_watch(
self, path: str, event_mask: InotifyMasks = None
if i call
wm = WatchManager()
wm.add_watch(H264PATH, event_mask=InotifyMasks.IN_CLOSE_WRITE, recursive=True)
then:
AttributeError
module 'trio' has no attribute 'hazmat'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.