source: neercs/trunk/src/python/py_module.c @ 4040

Last change on this file since 4040 was 4040, checked in by Jean-Yves Lamoureux, 11 years ago
  • Moved python stuff to src/python
File size: 2.3 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 */
40static struct screen_list *screen_list;
41
42PyObject *PyInit_neercs(void);
43
44static PyObject *neercs_get(PyObject * self, PyObject * args)
45{
46    char *s = NULL;
47
48    debug("Get using list at %p", screen_list);
49
50    if (!PyArg_ParseTuple(args, "s", &s))
51    {
52        debug("py Can't parse");
53        return NULL;
54    }
55    debug("py Argument : '%s'", s);
56    struct config_line *c = get_config(s);
57    debug("py config %p");
58
59    if (c)
60        return Py_BuildValue("s", c->get(screen_list));
61    else
62        return Py_BuildValue("s", "Invalid");
63
64}
65
66static PyObject *neercs_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,
76     "Return the specified variable's value."},
77    {NULL, NULL, 0, NULL}
78};
79
80static PyModuleDef NeercsModule = {
81    PyModuleDef_HEAD_INIT, "neercs", NULL, -1, NeercsMethods,
82    NULL, NULL, NULL, NULL
83};
84
85PyObject *PyInit_neercs(void)
86{
87    PyObject *o = PyModule_Create(&NeercsModule);
88    PyImport_AppendInittab("neercs", &PyInit_neercs);
89    return o;
90}
91
92void initNeercsModule(struct screen_list *sl)
93{
94    screen_list = sl;
95        PyInit_neercs();
96}
97
98
99
100#endif
Note: See TracBrowser for help on using the repository browser.