Anonymous avatar Anonymous committed 4353276

Minimal inotify wrapper.

Comments (0)

Files changed (4)

+build
+
+syntax: glob
+*~
+.*.swp
+*.py[co]

inotify/__init__.py

+from _inotify import *

inotify/_inotify.c

+#include <Python.h>
+#include <sys/inotify.h>
+
+static PyObject *pyinotify_init(PyObject *self, PyObject *args)
+{
+    PyObject *ret = NULL;
+    int fd = -1;
+    
+    if (!PyArg_ParseTuple(args, ":init"))
+	goto bail;
+    
+    fd = inotify_init();
+
+    if (fd == -1) {
+	printf("bail\n");
+	ret = PyErr_SetFromErrno(PyExc_OSError);
+	goto bail;
+    }
+	
+    ret = PyInt_FromLong(fd);
+    if (ret == NULL)
+	goto bail;
+
+    goto done;
+    
+bail:
+    if (fd != -1)
+	close(fd);
+
+    Py_XDECREF(ret);
+    
+done:
+    return ret;
+}
+
+static char init_doc[] =
+    "Initialise an inotify instance.\n"
+    "Returns a file descriptor associated with a new inotify event queue.";
+
+static PyMethodDef methods[] = {
+    {"init", pyinotify_init, METH_VARARGS, init_doc},
+    {NULL},
+};
+    
+static char doc[] = "Low-level inotify interface wrappers.";
+
+void init_inotify(void)
+{
+    PyObject *mod;
+
+    mod = Py_InitModule3("_inotify", methods, doc);
+}
+#!/usr/bin/env python
+
+import distutils.core
+import distutils.util
+
+platform = distutils.util.get_platform()
+
+if not platform.startswith('linux'):
+    raise Exception('inotify is linux-specific, and does not work on %s' %
+                    platform)
+
+distutils.core.setup(
+    name='inotify',
+    version='0.5',
+    description='Interface to Linux inotify service',
+    author="Bryan O'Sullivan",
+    author_email='bos@serpentine.com',
+    license='LGPL',
+    platforms='Linux',
+    packages=['inotify'],
+    ext_modules=[distutils.core.Extension('inotify._inotify', ['inotify/_inotify.c'])],
+    )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.