Skip to content

Commit

Permalink
Docs, version bump for release
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjbillington committed Nov 21, 2019
1 parent 7f7d6dc commit acb82f4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 70 deletions.
120 changes: 61 additions & 59 deletions README
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
inotify\_simple 1.1
===================
inotify_simple 1.2
==================

Project status: Stable. This project is in active use and is maintained.
Lack of repository activity does not imply abandonment: this is a simple
project that has met its goals, has no known bugs, and does not require
much maintenance to continue functioning. Please report any issues you
encounter and I will fix them in a timely manner if they are within the
scope of the project.

``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 122
fancy bells and whistles, just a literal wrapper with ctypes. Only 131
lines of code!

``inotify_init()`` is wrapped as a class that does little more than hold
Expand All @@ -26,22 +33,17 @@ to install ``inotify_simple``, run:

::

$ pip3 install inotify_simple
$ pip3 install inotify_simple

or to install from source:

::

$ python3 setup.py install
$ python3 setup.py install

Note: If on Python < 3.4, you'll need the backported `enum34
Note: If on Python < 3.4, youll 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
------------

Expand All @@ -52,7 +54,7 @@ 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
and nothing more. So hopefully if Ive written it right, it will remain
functional well into the future with no changes, recompilation or
attention on my part.

Expand All @@ -61,58 +63,58 @@ 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))
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
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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# inotify_simple 1.1
# inotify_simple 1.2

Project status: Stable. This project is in active use and is maintained. Lack of
repository activity does not imply abandonment: this is a simple project that has met
Expand Down
8 changes: 2 additions & 6 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inotify_simple |release|

``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 122
No fancy bells and whistles, just a literal wrapper with ctypes. Only 131
lines of code!

``inotify_init()`` is wrapped as a class that does little more than hold the
Expand Down Expand Up @@ -48,9 +48,6 @@ or to install from source:
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
Expand Down Expand Up @@ -179,8 +176,7 @@ Module reference
Full source code
----------------

Free to copy and paste into your project subject to the simplified BSD
license. Presented here for ease of verifying that this wrapper is as sensible
Presented here for ease of verifying that this wrapper is as sensible
as it claims to be (comments stripped - see source on github to see comments).

.. literalinclude:: fullsource.py
8 changes: 5 additions & 3 deletions inotify_simple/inotify_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ class INotify(object):
def __init__(self):
"""Object wrapper around ``inotify_init()`` which stores the inotify file
descriptor. Raises an OSError on failure. :func:`~inotify_simple.INotify.close`
should be called when no longer needed. Can be used as a context manager
to ensure it is closed."""
should be called when no longer needed. Can be used as a context manager to
ensure it is closed. This object has a `fileno()` method, and so can be used
directly with `select()` or other functions expecting a file-like object."""
#: The inotify file descriptor returned by ``inotify_init()``. You are
#: free to use it directly with ``os.read`` if you'd prefer not to call
#: :func:`~inotify_simple.INotify.read` for some reason.
Expand Down Expand Up @@ -150,12 +151,13 @@ def read(self, timeout=None, read_delay=None):
return events

def close(self):
"""Close the inotify file descriptor"""
"""Close the inotify file descriptor, if not already closed"""
if self.fd >= 0:
os.close(self.fd)
self.fd = -1

def fileno(self):
"""Return the file number of the underlying inotify file descriptor"""
return self.fd

def __enter__(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
from distutils.core import setup

__version__ = '1.1.8'
__version__ = '1.2.0'

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

0 comments on commit acb82f4

Please sign in to comment.