3 * Bacula interface to Python for the File Daemon
5 * Kern Sibbald, March MMV
12 Copyright (C) 2005 Kern Sibbald
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of
17 the License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public
25 License along with this program; if not, write to the Free
26 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 #undef _POSIX_C_SOURCE
38 PyObject *bacula_get(PyObject *self, PyObject *args);
39 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw);
41 /* Define Bacula entry points */
42 PyMethodDef BaculaMethods[] = {
43 {"get", bacula_get, METH_VARARGS, "Get Bacula FD variables."},
44 {"set", (PyCFunction)bacula_set, METH_VARARGS|METH_KEYWORDS,
45 "Set FD Bacula variables."},
46 {NULL, NULL, 0, NULL} /* last item */
55 static struct s_vars vars[] = {
56 { N_("FDName"), "s"}, /* 0 */
57 { N_("Level"), "s"}, /* 1 */
58 { N_("Type"), "s"}, /* 2 */
59 { N_("JobId"), "i"}, /* 3 */
60 { N_("Client"), "s"}, /* 4 */
61 { N_("JobName"), "s"}, /* 5 */
62 { N_("JobStatus"), "s"}, /* 6 */
67 /* Return Bacula variables */
68 PyObject *bacula_get(PyObject *self, PyObject *args)
77 if (!PyArg_ParseTuple(args, "Os:get", &CObject, &item)) {
80 jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
81 for (i=0; vars[i].name; i++) {
82 if (strcmp(vars[i].name, item) == 0) {
91 case 0: /* FD's name */
92 return Py_BuildValue(vars[i].fmt, my_name);
94 return Py_BuildValue(vars[i].fmt, job_level_to_str(jcr->JobLevel));
96 return Py_BuildValue(vars[i].fmt, job_type_to_str(jcr->JobType));
98 return Py_BuildValue(vars[i].fmt, jcr->JobId);
100 return Py_BuildValue(vars[i].fmt, jcr->client_name);
101 case 5: /* JobName */
102 return Py_BuildValue(vars[i].fmt, jcr->Job);
103 case 6: /* JobStatus */
105 buf[0] = jcr->JobStatus;
106 return Py_BuildValue(vars[i].fmt, buf);
111 /* Set Bacula variables */
112 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw)
117 static char *kwlist[] = {"jcr", "JobReport", NULL};
118 if (!PyArg_ParseTupleAndKeywords(args, keyw, "O|ss:set", kwlist,
122 jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
125 Jmsg(jcr, M_INFO, 0, "%s", msg);
127 return Py_BuildValue("i", 1);
130 #endif /* HAVE_PYTHON */