From 760f6b9f3ba29892fd9d4b640849f4f5a8656de6 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 5 Nov 2011 23:00:31 -0400 Subject: [PATCH] initial --- setup.py | 8 ++++++++ spammodule.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 setup.py create mode 100644 spammodule.c diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..443556f --- /dev/null +++ b/setup.py @@ -0,0 +1,8 @@ + +from distutils.core import setup, Extension + +module1 = Extension('spam', sources = ['spammodule.c']) + +setup(name = 'pkgname', version = '1.0', + description = 'this is the package description', + ext_modules = [module1]) diff --git a/spammodule.c b/spammodule.c new file mode 100644 index 0000000..bc98639 --- /dev/null +++ b/spammodule.c @@ -0,0 +1,29 @@ + +#include + +static PyObject * +spam_system(PyObject *self, PyObject *args) +{ + const char *command; + int sts; + + if (!PyArg_ParseTuple(args, "s", &command)) + return NULL; + sts = system(command); + return Py_BuildValue("i", sts); +} + +static PyMethodDef SpamMethods[] = { + {"system", spam_system, METH_VARARGS, "Execute a shell command."}, + {NULL, NULL, 0, NULL} +}; + +PyMODINIT_FUNC +initspam(void) +{ + PyObject *m; + + m = Py_InitModule("spam", SpamMethods); + if (m == NULL) + return; +}