inotify-simple


Nameinotify-simple JSON
Version 1.3.5 PyPI version JSON
download
home_pagehttps://github.com/chrisjbillington/inotify_simple
SummaryA simple wrapper around inotify. No fancy bells and whistles, just a literal wrapper with ctypes. Under 100 lines of code!
upload_time2020-08-06 00:24:00
maintainer
docs_urlNone
authorChris Billington
requires_python>=2.7, !=3.0.*, !=3.1.*
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # inotify_simple 1.3

`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  \~100
lines of code!

`inotify_init1()` is wrapped as a file-like object, `INotify()`, holding the inotify
file descriptor. `INotify().read()` 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 and
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).

## 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

```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.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/chrisjbillington/inotify_simple",
    "name": "inotify-simple",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*",
    "maintainer_email": "",
    "keywords": "",
    "author": "Chris Billington",
    "author_email": "chrisjbillington@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/51/41/59ca6011f5463d5e5eefcfed2e7fe470922d3a958b7f3aad95eda208d7d3/inotify_simple-1.3.5.tar.gz",
    "platform": "",
    "description": "# inotify_simple 1.3\n\n`inotify_simple` is a simple Python wrapper around\n[inotify](http://man7.org/linux/man-pages/man7/inotify.7.html).\nNo fancy bells and whistles, just a literal wrapper with ctypes. Only  \\~100\nlines of code!\n\n`inotify_init1()` is wrapped as a file-like object, `INotify()`, holding the inotify\nfile descriptor. `INotify().read()` reads available data from the file descriptor and\nreturns events as `namedtuple` objects after unpacking them with the `struct` module.\n`inotify_add_watch()` and `inotify_rm_watch()` are wrapped with no changes at all,\ntaking and returning watch descriptor integers that calling code is expected to keep\ntrack of itself, just as one would use `inotify` from C. Works with Python 2.7 and\nPython >= 3.2.\n\n[View on PyPI](http://pypi.python.org/pypi/inotify_simple) |\n[Fork me on github](https://github.com/chrisjbillington/inotify_simple) |\n[Read the docs](http://inotify_simple.readthedocs.org)\n\n\n## Installation\n\nto install `inotify_simple`, run:\n\n```\n$ pip3 install inotify_simple\n```\n\nor to install from source:\n\n```\n$ python3 setup.py install\n```\n\nNote:  If on Python < 3.4, you'll need the backported [enum34\nmodule](https://pypi.python.org/pypi/enum34).\n\n## Introduction\n\nThere are many inotify python wrappers out there. [I found them all\nunsatisfactory](https://xkcd.com/927/). Most are far too high-level for my\ntastes, and the supposed convenience they provide actually limits one from\nusing inotify in ways other than those the author imagined. Others are C\nextensions, requiring compilation for different platforms and Python versions,\nrather than a pure python module using ctypes. This one is pretty low-level\nand really just does what inotify itself does and nothing more. So hopefully\nif I've written it right, it will remain functional well into the future with\nno changes, recompilation or attention on my part.\n\n## Example usage\n\n```python\nimport os\nfrom inotify_simple import INotify, flags\n\nos.mkdir('/tmp/inotify_test')\n\ninotify = INotify()\nwatch_flags = flags.CREATE | flags.DELETE | flags.MODIFY | flags.DELETE_SELF\nwd = inotify.add_watch('/tmp/inotify_test', watch_flags)\n\n# Now create, delete and modify some files in the directory being monitored:\nos.chdir('/tmp/inotify_test')\n# CREATE event for a directory:\nos.system('mkdir foo')\n# CREATE event for a file:\nos.system('echo hello > test.txt')\n# MODIFY event for the file:\nos.system('echo world >> test.txt')\n# DELETE event for the file\nos.system('rm test.txt')\n# DELETE event for the directory\nos.system('rmdir foo')\nos.chdir('/tmp')\n# DELETE_SELF on the original directory. # Also generates an IGNORED event\n# indicating the watch was removed.\nos.system('rmdir inotify_test')\n\n# And see the corresponding events:\nfor event in inotify.read():\n    print(event)\n    for flag in flags.from_mask(event.mask):\n        print('    ' + str(flag))\n```\n\nThis outputs the following:\n```\nEvent(wd=1, mask=1073742080, cookie=0, name=u'foo')\n    flags.CREATE\n    flags.ISDIR\nEvent(wd=1, mask=256, cookie=0, name=u'test.txt')\n    flags.CREATE\nEvent(wd=1, mask=2, cookie=0, name=u'test.txt')\n    flags.MODIFY\nEvent(wd=1, mask=512, cookie=0, name=u'test.txt')\n    flags.DELETE\nEvent(wd=1, mask=1073742336, cookie=0, name=u'foo')\n    flags.DELETE\n    flags.ISDIR\nEvent(wd=1, mask=1024, cookie=0, name=u'')\n    flags.DELETE_SELF\nEvent(wd=1, mask=32768, cookie=0, name=u'')\n    flags.IGNORED\n```\n\nNote that the flags, since they are defined with an `enum.IntEnum`, print as\nwhat they are called rather than their integer values. However they are still\njust integers and so can be bitwise-ANDed and ORed etc with masks etc. The\n`flags.from_mask()` method bitwise-ANDs a mask with all possible flags and\nreturns a list of matches. This is for convenience and useful for debugging\nwhich events are coming through, but performance critical code should\ngenerally bitwise-AND masks with flags of interest itself so as to not do\nunnecessary checks.\n\n[See here](http://inotify_simple.readthedocs.org) for more.",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "A simple wrapper around inotify. No fancy bells and whistles, just a literal wrapper with ctypes. Under 100 lines of code!",
    "version": "1.3.5",
    "project_urls": {
        "Homepage": "https://github.com/chrisjbillington/inotify_simple"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "514159ca6011f5463d5e5eefcfed2e7fe470922d3a958b7f3aad95eda208d7d3",
                "md5": "b7ca2ffa816dea85ef5023cde4e72b8b",
                "sha256": "8440ffe49c4ae81a8df57c1ae1eb4b6bfa7acb830099bfb3e305b383005cc128"
            },
            "downloads": -1,
            "filename": "inotify_simple-1.3.5.tar.gz",
            "has_sig": false,
            "md5_digest": "b7ca2ffa816dea85ef5023cde4e72b8b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*",
            "size": 9747,
            "upload_time": "2020-08-06T00:24:00",
            "upload_time_iso_8601": "2020-08-06T00:24:00.561399Z",
            "url": "https://files.pythonhosted.org/packages/51/41/59ca6011f5463d5e5eefcfed2e7fe470922d3a958b7f3aad95eda208d7d3/inotify_simple-1.3.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-08-06 00:24:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "chrisjbillington",
    "github_project": "inotify_simple",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "inotify-simple"
}
        
Elapsed time: 0.28945s