Skip to content

Commit

Permalink
got docs working on PyPI again
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjbillington committed Nov 20, 2017
1 parent ddb9527 commit 517cc52
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 36 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include README.md
include README.rst
include LICENSE
include example.py
30 changes: 0 additions & 30 deletions README

This file was deleted.

126 changes: 126 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
inotify\_simple 1.1
===================

``inotify_simple`` is a simple Python wrapper around
`inotify <http://man7.org/linux/man-pages/man7/inotify.7.html>`__. No
fancy bells and whistles, just a literal wrapper with ctypes. Only 118
lines of code!

``inotify_init()`` is wrapped as a class that does little more than hold
the resulting inotify file descriptor. A ``read()`` method is provided
which reads available data from the file descriptor and returns events
as ``namedtuple`` objects after unpacking them with the ``struct``
module. ``inotify_add_watch()`` and ``inotify_rm_watch()`` are wrapped
with no changes at all, taking and returning watch descriptor integers
that calling code is expected to keep track of itself, just as one would
use inotify from C. Works with Python 2.7 or Python >= 3.2.

`View on PyPI <http://pypi.python.org/pypi/inotify_simple>`__ \| `Fork
me on github <https://github.com/chrisjbillington/inotify_simple>`__ \|
`Read the docs <http://inotify_simple.readthedocs.org>`__

Installation
------------

to install ``inotify_simple``, run:

::

$ pip3 install inotify_simple

or to install from source:

::

$ python3 setup.py install

Note: If on Python < 3.4, you'll need the backported `enum34
module <https://pypi.python.org/pypi/enum34>`__.

``inotify_simple`` is a small amount of code and unlikely to change much
in the future until inotify itself or Python changes, so you can also
just copy and paste it into your project to avoid the extra dependency
with pretty low risk.

Introduction
------------

There are many inotify python wrappers out there. `I found them all
unsatisfactory <https://xkcd.com/927/>`__. Most are far too high-level
for my tastes, and the supposed convenience they provide actually limits
one from using inotify in ways other than those the author imagined.
Others are C extensions, requiring compilation for different platforms
and Python versions, rather than a pure python module using ctypes. This
one is pretty low-level and really just does what inotify itself does
and nothing more. So hopefully if I've written it right, it will remain
functional well into the future with no changes, recompilation or
attention on my part.

Example usage
-------------

.. code:: python
import os
from inotify_simple import INotify, flags
os.mkdir('/tmp/inotify_test')
inotify = INotify()
watch_flags = flags.CREATE | flags.DELETE | flags.MODIFY | flags.DELETE_SELF
wd = inotify.add_watch('/tmp/inotify_test', watch_flags)
# Now create, delete and modify some files in the directory being monitored:
os.chdir('/tmp/inotify_test')
# CREATE event for a directory:
os.system('mkdir foo')
# CREATE event for a file:
os.system('echo hello > test.txt')
# MODIFY event for the file:
os.system('echo world >> test.txt')
# DELETE event for the file
os.system('rm test.txt')
# DELETE event for the directory
os.system('rmdir foo')
os.chdir('/tmp')
# DELETE_SELF on the original directory. # Also generates an IGNORED event
# indicating the watch was removed.
os.system('rmdir inotify_test')
# And see the corresponding events:
for event in inotify.read():
print(event)
for flag in flags.from_mask(event.mask):
print(' ' + str(flag))
This outputs the following:

::

Event(wd=1, mask=1073742080, cookie=0, name=u'foo')
flags.CREATE
flags.ISDIR
Event(wd=1, mask=256, cookie=0, name=u'test.txt')
flags.CREATE
Event(wd=1, mask=2, cookie=0, name=u'test.txt')
flags.MODIFY
Event(wd=1, mask=512, cookie=0, name=u'test.txt')
flags.DELETE
Event(wd=1, mask=1073742336, cookie=0, name=u'foo')
flags.DELETE
flags.ISDIR
Event(wd=1, mask=1024, cookie=0, name=u'')
flags.DELETE_SELF
Event(wd=1, mask=32768, cookie=0, name=u'')
flags.IGNORED

Note that the flags, since they are defined with an ``enum.IntEnum``,
print as what they are called rather than their integer values. However
they are still just integers and so can be bitwise-ANDed and ORed etc
with masks etc. The ``flags.from_mask()`` method bitwise-ANDs a mask
with all possible flags and returns a list of matches. This is for
convenience and useful for debugging which events are coming through,
but performance critical code should generally bitwise-AND masks with
flags of interest itself so as to not do unnecessary checks.

`See here <http://inotify_simple.readthedocs.org>`__ for more.
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
# If the package is not registered with PyPI yet, do so with:
# python setup.py register

import pypandoc
with open('README.rst', 'w') as f:
f.write(pypandoc.convert('README.md', 'rst', format='markdown'))

import os
from distutils.core import setup

__version__ = '1.1.2'
__version__ = '1.1.5'

DESCRIPTION = \
"""A simple wrapper around inotify. No fancy bells and whistles, just a
literal wrapper with ctypes. Only 118 lines of code!
"""
DESCRIPTION = ("A simple wrapper around inotify. No fancy bells and whistles, " +
"just a literal wrapper with ctypes. Only 118 lines of code!")

# Auto generate a __version__ package for the package to import
with open(os.path.join('inotify_simple', '__version__.py'), 'w') as f:
Expand All @@ -22,6 +24,7 @@
setup(name='inotify_simple',
version=__version__,
description=DESCRIPTION,
long_description=open('README.rst').read(),
author='Chris Billington',
author_email='[email protected]',
url='https://github.com/chrisjbillington/inotify_simple',
Expand Down

0 comments on commit 517cc52

Please sign in to comment.