summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2008-01-03 15:39:19 -0500
committerTheodore Ts'o <tytso@mit.edu>2008-01-03 15:39:19 -0500
commit1725c0cf530eec737b9d1ed008e0be8bfb7fcb4f (patch)
tree3bbc108b1c74ed8cc55936f8db018e3724d92485
parentb05d4ab635196f1e45bb7a11914edb2b0877274c (diff)
downloade2fsprogs-1725c0cf530eec737b9d1ed008e0be8bfb7fcb4f.tar.gz
Add sample python bindings for the uuid library
Pretty trivial, but maybe useful to someone. Originially submited by Ondrej Sury <ondrej@sury.org> Addresses-Sourceforge-Patches: #778817 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rwxr-xr-xcontrib/python-uuid/setup.py11
-rwxr-xr-xcontrib/python-uuid/test.py18
-rw-r--r--contrib/python-uuid/uuid.c23
3 files changed, 52 insertions, 0 deletions
diff --git a/contrib/python-uuid/setup.py b/contrib/python-uuid/setup.py
new file mode 100755
index 00000000..3934d170
--- /dev/null
+++ b/contrib/python-uuid/setup.py
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+from distutils.core import setup, Extension
+
+uuid = Extension('e2fsprogs_uuid',
+ sources = ['uuid.c'],
+ libraries = ['uuid'])
+
+setup (name = 'e2fsprogs_uuid',
+ version = '1.0',
+ description = 'This is python uuid interface',
+ ext_modules = [uuid])
diff --git a/contrib/python-uuid/test.py b/contrib/python-uuid/test.py
new file mode 100755
index 00000000..2264f623
--- /dev/null
+++ b/contrib/python-uuid/test.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+import e2fsprogs_uuid
+import time
+
+print "Generating uuid...",
+try:
+ time = time.time()
+ u = e2fsprogs_uuid.generate()
+except:
+ u = "FAIL"
+print u, "...", time
+
+print "Calling generate with param...",
+try:
+ e2fsprogs_uuid.generate("param")
+ print "FAIL."
+except:
+ print "OK"
diff --git a/contrib/python-uuid/uuid.c b/contrib/python-uuid/uuid.c
new file mode 100644
index 00000000..34dd56a0
--- /dev/null
+++ b/contrib/python-uuid/uuid.c
@@ -0,0 +1,23 @@
+#include <Python.h>
+#include <time.h>
+#include <uuid/uuid.h>
+
+static PyObject * _uuid_generate(PyObject *self, PyObject *args)
+{
+ uuid_t u;
+ char uuid[37];
+ if (!PyArg_ParseTuple(args, "")) return NULL;
+ uuid_generate(u);
+ uuid_unparse(u, uuid);
+ return Py_BuildValue("s", uuid);
+}
+
+static PyMethodDef _uuid_methods[] = {
+ {"generate", _uuid_generate, METH_VARARGS, "Generate UUID"},
+ {NULL, NULL, 0, NULL}
+};
+
+void inite2fsprogs_uuid(void)
+{
+ (void) Py_InitModule("e2fsprogs_uuid", _uuid_methods);
+}