Exemple #1
0
/* Call python function to initialize the python script */
int
ices_playlist_python_initialize (playlist_module_t* pm)
{
    PyObject* res;
    int rc = 1;

    pm->get_next = playlist_python_get_next;
    pm->get_metadata = playlist_python_get_metadata;
    pm->get_lineno = playlist_python_get_lineno;
    pm->reload = playlist_python_reload;
    pm->shutdown = playlist_python_shutdown;

    if (python_init () < 0)
        return -1;

    if (pl_init_hook) {
        if ((res = python_eval (pl_init_hook)) && PyInt_Check (res))
            rc = PyInt_AsLong (res);
        else
            ices_log_error ("ices_init failed");

        Py_XDECREF (res);
    }

    return rc;
}
/* Call python function to shutdown the script */
static void playlist_python_shutdown(void) {
	PyObject* res;

	if (pl_shutdown_hook) {
		if (!((res = python_eval(pl_shutdown_hook)) && PyInt_Check(res)))
			ices_log_error("ices_shutdown failed");

		Py_XDECREF(res);
	}

	python_shutdown();
}
/* Call python function to get next file to play */
static char *playlist_python_get_next(void) {
	PyObject* res;
	char* rc = NULL;

	if ((res = python_eval(pl_get_next_hook)) && PyString_Check(res))
		rc = ices_util_strdup(PyString_AsString(res));
	else
		ices_log_error("ices_get_next failed");

	Py_XDECREF(res);

	return rc;
}
/* Call the python function to get the current line number */
static int playlist_python_get_lineno(void) {
	PyObject* res;
	int rc = 0;

	if (pl_get_lineno_hook) {
		if ((res = python_eval(pl_get_lineno_hook)) && PyInt_Check(res))
			rc = PyInt_AsLong(res);
		else
			ices_log_error("ices_get_lineno failed");

		Py_XDECREF(res);
	}

	return rc;
}
Exemple #5
0
static int
Python_Eval_Cmd(ClientData cdata, Tcl_Interp *interp,
                int objc, Tcl_Obj *const objv[])
{
  TCL_ARGS(4);
  int rc;
  int persist;
  rc = Tcl_GetBooleanFromObj(interp, objv[1], &persist);
  TCL_CHECK_MSG(rc, "first arg should be integer!");
  char* code = Tcl_GetString(objv[2]);
  char* expression = Tcl_GetString(objv[3]);
  Tcl_Obj* result = NULL;
  rc = python_eval(persist, code, expression, &result);
  TCL_CHECK(rc);
  Tcl_SetObjResult(interp, result);
  return TCL_OK;
}