emctoo / aionotify

Simple, asyncio-based inotify library for Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aionotify

https://secure.travis-ci.org/rbarrois/aionotify.png?branch=master Latest Version Supported Python versions Wheel status License

aionotify is a simple, asyncio-based inotify library.

Its use is quite simple:

import asyncio
import aionotify

# Setup the watcher
watcher = aionotify.Watcher()
watcher.watch(alias='logs', path='/var/log', flags=aionotify.Flags.MODIFY)

# Prepare the loop
loop = asyncio.get_event_loop()

async def work():
    await watcher.setup(loop)
    for _i in range(10):
        # Pick the 10 first events
        event = await watcher.get_event()
        print(event)
    watcher.close()

loop.run_until_complete(work())
loop.stop()
loop.close()

Links

Events

An event is a simple object with a few attributes:

  • name: the path of the modified file
  • flags: the modification flag; use aionotify.Flags.parse() to retrieve a list of individual values.
  • alias: the alias of the watch triggering the event
  • cookie: for renames, this integer value links the "renamed from" and "renamed to" events.

Watches

aionotify uses a system of "watches", similar to inotify.

A watch may have an alias; by default, it uses the path name:

watcher = aionotify.Watcher()
watcher.watch('/var/log', flags=aionotify.Flags.MODIFY)

# Similar to:
watcher.watch('/var/log', flags=aionotify.Flags.MODIFY, alias='/var/log')

A watch can be removed by using its alias:

watcher = aionotify.Watcher()
watcher.watch('/var/log', flags=aionotify.Flags.MODIFY)

watcher.unwatch('/var/log')

About

Simple, asyncio-based inotify library for Python

License:BSD 2-Clause "Simplified" License


Languages

Language:Python 99.4%Language:Makefile 0.6%