source: neercs/trunk/src/py_module.c @ 4038

Last change on this file since 4038 was 4038, checked in by Jean-Yves Lamoureux, 10 years ago
  • Better python command handling
  • Added get(str) to neercs python module, doesn't work as I would like to
  • Avoid redefining everything while including neercs.h several times
File size: 2.2 KB
Line 
1/*
2 *  neercs        console-based window manager
3 *  Copyright (c) 2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  $Id: py_module.c 3996 2009-11-22 12:41:45Z jylam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16
17#ifdef USE_PYTHON
18
19#include <Python.h>
20#include "py_module.h"
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <unistd.h>
26
27#include <fcntl.h>
28#include <signal.h>
29#include <sys/ioctl.h>
30#include <sys/socket.h>
31#include <sys/time.h>
32#include <time.h>
33#include <sys/wait.h>
34#include <sys/types.h>
35#include <caca.h>
36
37#include "neercs.h"
38
39/* FIXME : Find a way to pass a user pointer to PyModuleDef or something */
40struct screen_list *screen_list;
41
42static PyObject*
43neercs_get(PyObject *self, PyObject *args)
44{
45    char *s = NULL;
46   
47    debug("Get using list at %p\n", screen_list);
48   
49    if(!PyArg_ParseTuple(args, "s", &s))
50    {
51        debug("py Can't parse\n");
52        return NULL;
53    }
54    debug("py Argument : '%s'\n", s);
55    struct config_line *c = get_config(s);
56    debug("py config %p\n");
57   
58    if(c)
59        return Py_BuildValue("s", c->get(screen_list));
60    else
61        return Py_BuildValue("s", "Invalid");
62
63}
64
65static PyObject*
66neercs_version(PyObject *self, PyObject *args)
67{
68    if(!PyArg_ParseTuple(args, ":version"))
69        return NULL;
70    return Py_BuildValue("s", PACKAGE_VERSION);
71}
72
73static PyMethodDef NeercsMethods[] = {
74    {"version", neercs_version, METH_VARARGS,  "Return the neercs version."},
75    {"get", neercs_get, METH_VARARGS,  "Return the specified variable's value."},
76    {NULL, NULL, 0, NULL}
77};
78
79static PyModuleDef NeercsModule = {
80    PyModuleDef_HEAD_INIT, "neercs", NULL, -1, NeercsMethods,
81    NULL, NULL, NULL, NULL
82};
83
84PyObject* PyInit_neercs(struct screen_list* sl)
85{
86    screen_list = sl;
87    PyObject* o =  PyModule_Create(&NeercsModule);
88    PyImport_AppendInittab("neercs", &PyInit_neercs);
89    return o;
90}
91
92
93
94
95
96#endif
Note: See TracBrowser for help on using the repository browser.