Commits

Anonymous committed 9b5c033

initial commit

Comments (0)

Files changed (3)

+cmake_minimum_required(VERSION 2.8)
+project(spam)
+
+
+find_package(PythonLibs REQUIRED)
+include_directories(${PYTHON_INCLUDE_DIRS})
+
+
+add_library(spam SHARED main.cpp)
+target_link_libraries(spam ${PYTHON_LIBRARY})
+set_target_properties(spam PROPERTIES PREFIX "" SUFFIX ".so")
+#include <Python.h>
+
+static PyObject *SpamError;
+
+
+static PyObject * spam_system(PyObject *self, PyObject *args)
+{
+    const char *command;
+    int sts;
+
+    if (!PyArg_ParseTuple(args, "s", &command))
+        return NULL;
+    sts = system(command);
+    if (sts < 0) {
+        PyErr_SetString(SpamError, "System command failed");
+        return NULL;
+    }
+    return PyLong_FromLong(sts);
+}
+
+
+static PyMethodDef SpamMethods[] = {
+    {"system",  spam_system, METH_VARARGS, "Execute a shell command."},
+    {NULL, NULL, 0, NULL}        /* Sentinel */
+};
+
+PyMODINIT_FUNC
+initspam(void)
+{
+    PyObject *m;
+
+    m = Py_InitModule("spam", SpamMethods);
+    if (m == NULL)
+        return;
+
+    SpamError = PyErr_NewException((char*)"spam.error", NULL, NULL);
+    Py_INCREF(SpamError);
+    PyModule_AddObject(m, "error", SpamError);
+}
+from distutils.core import setup, Extension
+
+module1 = Extension('spam',
+                    sources = ['main.cpp'])
+
+setup (name = 'spam',
+       version = '1.0',
+       description = 'This is a demo package',
+       ext_modules = [module1])