1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
aionotify
=========
.. image:: https://secure.travis-ci.org/rbarrois/aionotify.png?branch=master
:target: http://travis-ci.org/rbarrois/aionotify/
.. image:: https://img.shields.io/pypi/v/aionotify.svg
:target: http://aionotify.readthedocs.org/en/latest/changelog.html
:alt: Latest Version
.. image:: https://img.shields.io/pypi/pyversions/aionotify.svg
:target: https://pypi.python.org/pypi/aionotify/
:alt: Supported Python versions
.. image:: https://img.shields.io/pypi/wheel/aionotify.svg
:target: https://pypi.python.org/pypi/aionotify/
:alt: Wheel status
.. image:: https://img.shields.io/pypi/l/aionotify.svg
:target: https://pypi.python.org/pypi/aionotify/
:alt: License
``aionotify`` is a simple, asyncio-based inotify library.
Its use is quite simple:
.. code-block:: python
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_eventloop()
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_completed(work())
loop.stop()
loop.close()
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:
.. code-block:: python
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:
.. code-block:: python
watcher = aionotify.Watcher()
watcher.watch('/var/log', flags=aionotify.Flags.MODIFY)
watcher.unwatch('/var/log')
|