Package: minotaur
Minotaur: A pythonic, asynchronous, inotify interfaceExamplesMinotaur provides theInotifyclass which is to be used as a context
manager, from within which, one may iterate over inotify events:withInotify()asn:n.add_watch('.',Mask.CREATE|Mask.DELETE|Mask.MOVE)forevtinn:print(evt)The asynchronous interface works almost identically. The inotify object must
be created in nonblocking mode, and then the mere addition of theasynckeyword to the iteration over events is all that's required:withInotify(blocking=False)asn:n.add_watch('.',Mask.CREATE|Mask.DELETE|Mask.MOVE)asyncforevtinn:print(evt)Example output would look like this:Event(wd=1,mask=<Mask.CREATE:256>,cookie=0,name=PosixPath('foo'))Event(wd=1,mask=<Mask.CREATE:256>,cookie=0,name=PosixPath('bar'))Event(wd=1,mask=<Mask.MOVED_FROM:64>,cookie=129399,name=PosixPath('foo'))Event(wd=1,mask=<Mask.MOVED_TO:128>,cookie=129399,name=PosixPath('baz'))Event(wd=1,mask=<Mask.DELETE:512>,cookie=0,name=PosixPath('bar'))Event(wd=1,mask=<Mask.DELETE:512>,cookie=0,name=PosixPath('baz'))There is also a command-line tool demonstrating the features$python-mminotaur--help

usage:minotaur[-h][--async|--sync][--fancy][--maskMASK]dir[dir...]Minotaur:Apythonic,asynchronous,inotifyinterface.

Asummaryofinotifywatchflags:-ACCESS:Filewasaccessed-ATTRIB:Metaatachanged,eg.permissions-CLOSE_WRITE:Fileforwritingwasclosed-CLOSE_NOWRITE:Fileordirnotopenedforwritingwasclosed-CREATE:File/dirwascreated-DELETE:Fileordirwasdeleted-DELETE_SELF:Watchedfile/dirwasitselfdeleted-MODIFY:Filewasmodified-MOVE_SELF:Watchedfile/dirwasitselfmoved-MOVED_FROM:Generatedfordircontainingoldfilenamewhenafileisrenamed-MOVED_TO:Generatedfordircontainingnewfilenamewhenafileisrenamed-OPEN:Fileordirwasopened-MOVE:MOVED_FROM|MOVED_TO-CLOSE:IN_CLOSE_WRITE|IN_CLOSE_NOWRITE-DONT_FOLLOW:Don't dereference pathname if it is a symbolic link- EXCL_UNLINK: Don'tgenerateeventsafterfileshavebeenunlinked-ONESHOT:Onlygenerateoneeventforthiswatch-ONLYDIR:Watchpathnameonlyifitisadir-MASK_CREATE:Onlywatchpathifitisn'talreadybeingwatched

positionalarguments:dirWatchforeventsingivendir

optionalarguments:-h,--helpshowthishelpmessageandexit--async,-aUseasyncioeventloop--sync,-sUsesynchronousinterface--fancy,-fUsefancyinterface--maskMASK,-mMASKEventstowatchforWhat is different about Minotaur?C interface provides basic wrapper to syscalls and constants. In future, if
performance becomes a problem, more functionality can be gradually moved
there.Pythonic.IntFlagsis used for watch types. Context-managers take care of
fd lifetime,close()method is idempotent. Rawread()andreadall()methods work comparably to python standardioobjects. Full support formypy, including typeshed for C interface. Iterator and async-iterator
protocols supported.Makes no assumptions about the name encoding of filesystems, ie. withos.fsencode()andos.fsdecode()Async interface supports multiple concurrent waiters. Waiting tasks are
woken in a first-come, first-serve manner.Users can choose between different levels of support:Raw syscall interfaceLow-level inotify object, which takes care of path encoding, reading of
raw inotify data, parsing of binary events in to python objects, and
provides both synchronous and async interface. But is still low-level
because it does no special handling of watches or combining of related
events (eg.MOVE_FROM/MOVE_TO).Fancy high-level interfaces, in pure python, built on top of low-level
interface.What is missingThere is no attempt to abstract file-notification functionality offered by
other operating systems in to a cross-platform interface.There are no tests.DevelopmentYou should use the provided pre-commit hooks to make sure code type-checks and
is PEP-8 formatted:ln-sf../../pre-commit.sh.git/hooks/pre-commitWhy another one?There are several other python inotify packages. So why does this one exist?
Well, this can perhaps be explained best by referring to some of the others:PyInotify: suffers from numerous bugs. The fd closes aren't idempotent,
this can lead to closing unrelated file descriptors. This would be less of
an issue if the fd had a clear ownership and lifetime, or used context
managers. In other words, it's difficult to use safely.PyInotify: Assumes utf-8 filesystem encoding. Noasynciointerface.inotify_simple: Nicely subclassesFileIO, but that precludesasynciosinceFileIOis meant for blocking I/O on files and cannot be easily
adapted for other purposes.python_inotify: Noasynciointerface and, it would need to be added in
the C code, or if added in python code would duplicate the C code and work
differently, thus being a new API.python-inotify: It's packaged by RedHat but, similarly topython_inotifythe read() syscall is done in the C extension so it
doesn't supportasyncio, and can't easily be adapted to do so without
changing the interface or duplicating functionality.asyncinotify: Easily the best of the bunch. The main downside is that it
doesn't provide a synchronous interface or low-level interfaces.The others seem to be parts of larger projects, or systems.