Author: mzugec
Date: Fri Mar 27 17:08:07 2009
New Revision: 56452
URL: http://svn.opensuse.org/viewcvs/yast?rev=56452&view=rev
Log:
initial commit
Added:
branches/tmp/mzugec/python-hd/
branches/tmp/mzugec/python-hd/Makefile
branches/tmp/mzugec/python-hd/pyhd.c
Added: branches/tmp/mzugec/python-hd/Makefile
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mzugec/python-hd/Makefile?rev=56452&view=auto
==============================================================================
--- branches/tmp/mzugec/python-hd/Makefile (added)
+++ branches/tmp/mzugec/python-hd/Makefile Fri Mar 27 17:08:07 2009
@@ -0,0 +1,6 @@
+CC = gcc
+CCFLAGS = -shared -I/usr/include/python2.6/ -L/usr/lib -lhd $(python-config --ldflags)
+
+pyhd.so: pyhd.c
+ ${CC} ${CCFLAGS} pyhd.c -o $@
+
Added: branches/tmp/mzugec/python-hd/pyhd.c
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mzugec/python-hd/pyhd.c?rev=56452&view=auto
==============================================================================
--- branches/tmp/mzugec/python-hd/pyhd.c (added)
+++ branches/tmp/mzugec/python-hd/pyhd.c Fri Mar 27 17:08:07 2009
@@ -0,0 +1,61 @@
+#include
+#include
+#include // libhd
+
+static PyObject * pyhd_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 PyObject * pyhd_probe(PyObject *self, PyObject *args)
+{
+ const char *command;
+ int sts;
+
+ if (!PyArg_ParseTuple(args, "s", &command))
+ return NULL;
+ sts = printf("Probing : %s\n", command);
+ return Py_BuildValue("i", sts);
+}
+
+static PyMethodDef HwinfoMethods[] = {
+ {"system", pyhd_system, METH_VARARGS, "Execute a shell command."},
+ {"probe", pyhd_probe, METH_VARARGS, "Probe devices."},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+static PyObject *PyhdError;
+
+PyMODINIT_FUNC initpyhd(void)
+{
+ PyObject *m;
+
+ m = Py_InitModule("pyhd", HwinfoMethods);
+ if (m == NULL)
+ return;
+
+ PyhdError = PyErr_NewException("spam.error", NULL, NULL);
+ Py_INCREF(PyhdError);
+ PyModule_AddObject(m, "error", PyhdError);
+}
+
+
+int main(int argc, char *argv[])
+{
+ /* Pass argv[0] to the Python interpreter */
+ Py_SetProgramName(argv[0]);
+
+ /* Initialize the Python interpreter. Required. */
+ Py_Initialize();
+
+ /* Add a static module */
+ initpyhd();
+
+ Py_Finalize();
+}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org