source: trunk/lang/python/Rappture/PyRpUtils.cc @ 4346

Last change on this file since 4346 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 2.1 KB
Line 
1
2/*
3 * Rappture Utils Python Interface
4 *
5 * ======================================================================
6 *  Derrick S. Kearney, Purdue University
7 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
8 *
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13#include <Python.h>
14#include <rappture.h>
15
16static PyObject *ErrorObject;
17
18PyDoc_STRVAR(RpUtils_progress_doc,
19"progress (percent,message)\n\
20\n\
21Send progress messages to Rappture for updating the\n\
22graphical user interface's progress bar.");
23
24static PyObject*
25RpUtils_progress(PyObject *self, PyObject *args, PyObject *keywds)
26{
27    double pct;
28    char *msg;
29    static char *kwlist[] = {
30        (char *)"percent", (char *)"message", NULL
31    };
32    if (PyTuple_Size(args) != 2) {
33        PyErr_Format(PyExc_ValueError,
34                "progress() takes exactly 2 arguments, got %ld",
35                PyTuple_Size(args));
36        return NULL;
37    }
38    if (!PyArg_ParseTupleAndKeywords(args, keywds, "ds", kwlist,
39                &pct, &msg)) {
40        return NULL;
41    }
42    if (Rappture::Utils::progress((int)pct, msg) != 0) {
43        PyErr_SetString(PyExc_RuntimeError, "Error while writing to stdout");
44        return NULL;
45    }
46    Py_INCREF(Py_None);
47    return Py_None;
48}
49
50/* ---------- */
51
52
53/* List of functions defined in the module */
54
55static PyMethodDef RpUtils_Methods[] = {
56
57    {"progress", (PyCFunction)RpUtils_progress, METH_VARARGS|METH_KEYWORDS,
58        RpUtils_progress_doc},
59
60    {NULL,        NULL}        /* sentinel */
61};
62
63PyDoc_STRVAR(module_doc, "Rappture Utils Module for Python.");
64
65/* Initialization function for the module */
66
67PyMODINIT_FUNC
68initUtils(void)
69{
70    PyObject *m;
71
72    /* Create the module and add the functions */
73    m = Py_InitModule3("Utils", RpUtils_Methods, module_doc);
74
75    if (ErrorObject == NULL) {
76        ErrorObject = PyErr_NewException((char *)"Rappture.Utils.error",
77                NULL, NULL);
78        if (ErrorObject == NULL)
79            return;
80    }
81    Py_INCREF(ErrorObject);
82    PyModule_AddObject(m, "error", ErrorObject);
83
84    return;
85}
Note: See TracBrowser for help on using the repository browser.