Changeset 4038


Ignore:
Timestamp:
Nov 25, 2009, 4:07:46 PM (14 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • 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
Location:
neercs/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/configuration.c

    r4022 r4038  
    6767     get_window_manager},
    6868    {.name = "socket_dir",.set = set_socket_dir,.get = get_window_manager},
    69     {.name = "delay",.set = set_delay,.get = NULL},
     69    {.name = "delay",.set = set_delay,.get = get_delay},
    7070
    7171    {.name = "last",.set = NULL},
     
    322322{
    323323    int i = 0;
     324   
     325    debug("Looking for '%s'\n", name);
     326   
    324327    while (strncmp(config_option[i].name, "last", strlen("last")))
    325328    {
     329        debug("%d Testing against '%s'\n", i, config_option[i].name);
    326330        if (!strncmp(name, config_option[i].name, strlen(name)))
    327331        {
     
    476480char *get_window_manager(struct screen_list *screen_list)
    477481{
     482    debug("Window manager is %d\n", screen_list->wm_type);
    478483    switch (screen_list->wm_type)
    479484    {
     
    487492        return "hsplit";
    488493    default:
    489         return "invalid";
     494        return "invalid window manager";
    490495    }
    491496    return NULL;                /* Not reached */
  • neercs/trunk/src/interpreter.c

    r4037 r4038  
    182182    Py_Initialize();
    183183   
    184     PyInit_neercs();
     184    PyInit_neercs(sl);
    185185   
    186186    return 0;
     
    219219    }
    220220   
    221     PyObject *pModule, *pName, *pFunc, *pValue;
     221    PyObject *pModule, *pName, *pFunc;
    222222
    223223    /* Module from which to call the function */
     
    236236    if (pModule != NULL)
    237237    {
    238         pFunc = PyObject_GetAttrString(pModule, sl->interpreter_props.command);
    239         if (pFunc && PyCallable_Check(pFunc))
     238                PyObject *o = PyRun_String(sl->interpreter_props.command, Py_eval_input, PyModule_GetDict(pModule), NULL);
     239        debug("py object is %p\n", o);
     240        if(!o)
    240241        {
    241             pValue = PyObject_CallObject(pFunc, NULL);
    242             if (pValue != NULL) {
    243                 char *res = getStringFromPyObject(pValue);
    244                 sl->interpreter_props.output_res = res;
    245                 debug("py Result of call: %s\n", res);
    246                 Py_DECREF(pValue);
    247                 err = 2;
    248             }
    249             else {
    250                 Py_DECREF(pFunc);
    251                 Py_DECREF(pModule);
    252                 sl->interpreter_props.output_err = getPythonError();
    253                 err = 1;
    254                 debug("py Call failed\n");
    255                 goto end;
    256                 return 1;
    257             }
     242                sl->interpreter_props.output_err = getPythonError();   
     243            err = 1;
    258244        }
    259245        else
    260246        {
    261             sl->interpreter_props.output_err = getPythonError();
     247            debug("py res : %s\n", getStringFromPyObject(o));
     248            sl->interpreter_props.output_res = getStringFromPyObject(o);
    262249            err = 1;
    263             debug("py Error 2\n");
    264             goto end;
    265250        }
     251                goto end;
     252           
    266253    }
    267254    else
     
    299286    PyErr_Fetch(&type, &value, &traceback);
    300287
    301     char *etype = getStringFromPyObject(type);
    302288    char *evalue = getStringFromPyObject(value);
    303289
  • neercs/trunk/src/neercs.h

    r4037 r4038  
    1414 */
    1515
     16#ifndef _NEERCS_H_
     17#define _NEERCS_H_
     18
    1619#include <stdint.h>
    17 
    1820#include <caca.h>
    1921
     
    361363int get_key_value(char *line, struct option *option);
    362364int fill_config(struct screen_list *screen_list);
    363 
     365struct config_line *get_config(const char *name);
    364366
    365367/* Python interpreter */
     
    386388#   define debug(format, ...) do {} while(0)
    387389#endif
    388 
     390#endif /* _NEERCS_H_ */
  • neercs/trunk/src/py_module.c

    r4035 r4038  
    3737#include "neercs.h"
    3838
     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}
    3964
    4065static PyObject*
     
    4772
    4873static PyMethodDef NeercsMethods[] = {
    49     {"version", neercs_version, METH_VARARGS,
    50         "Return the neercs version."},
     74    {"version", neercs_version, METH_VARARGS,  "Return the neercs version."},
     75    {"get", neercs_get, METH_VARARGS,  "Return the specified variable's value."},
    5176    {NULL, NULL, 0, NULL}
    5277};
     
    5782};
    5883
    59 PyObject* PyInit_neercs(void)
     84PyObject* PyInit_neercs(struct screen_list* sl)
    6085{
     86    screen_list = sl;
    6187    PyObject* o =  PyModule_Create(&NeercsModule);
    6288    PyImport_AppendInittab("neercs", &PyInit_neercs);
  • neercs/trunk/src/py_module.h

    r4035 r4038  
    1818
    1919#include <Python.h>
     20#include "neercs.h"
    2021
    21 PyObject* PyInit_neercs(void);
     22PyObject* PyInit_neercs(struct screen_list* sl);
    2223
    2324
  • neercs/trunk/src/server.c

    r4033 r4038  
    385385{
    386386    int i;
     387    debug("Screen list at %p\n", screen_list);
     388   
    387389    /* Create socket and bind it */
    388390    create_socket(screen_list, SOCK_SERVER);
Note: See TracChangeset for help on using the changeset viewer.