3 * Bacula interface to Python for the Storage Daemon
5 * Kern Sibbald, January MMV
13 Copyright (C) 2005 Kern Sibbald
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of
18 the License, or (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public
26 License along with this program; if not, write to the Free
27 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
36 #undef _POSIX_C_SOURCE
39 PyObject *bacula_get(PyObject *self, PyObject *args);
40 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw);
42 /* Define Bacula entry points */
43 PyMethodDef BaculaMethods[] = {
44 {"get", bacula_get, METH_VARARGS, "Get Bacula variables."},
45 {"set", (PyCFunction)bacula_set, METH_VARARGS|METH_KEYWORDS,
46 "Set Bacula variables."},
47 {NULL, NULL, 0, NULL} /* last item */
56 static struct s_vars vars[] = {
57 { N_("Job"), "s"}, /* 0 */
58 { N_("SDName"), "s"}, /* 1 */
59 { N_("Level"), "s"}, /* 2 */
60 { N_("Type"), "s"}, /* 3 */
61 { N_("JobId"), "i"}, /* 4 */
62 { N_("Client"), "s"}, /* 5 */
63 { N_("Pool"), "s"}, /* 6 */
64 { N_("MediaType"), "s"}, /* 7 */
65 { N_("JobName"), "s"}, /* 8 */
66 { N_("JobStatus"), "s"}, /* 9 */
67 { N_("VolumeName"), "s"}, /* 10 */
68 { N_("Device"), "s"}, /* 11 */
73 /* Return Bacula variables */
74 PyObject *bacula_get(PyObject *self, PyObject *args)
83 if (!PyArg_ParseTuple(args, "Os:get", &CObject, &item)) {
86 jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
87 for (i=0; vars[i].name; i++) {
88 if (strcmp(vars[i].name, item) == 0) {
98 return Py_BuildValue(vars[i].fmt, jcr->job_name); /* Non-unique name */
99 case 1: /* SD's name */
100 return Py_BuildValue(vars[i].fmt, my_name);
102 return Py_BuildValue(vars[i].fmt, job_level_to_str(jcr->JobLevel));
104 return Py_BuildValue(vars[i].fmt, job_type_to_str(jcr->JobType));
106 return Py_BuildValue(vars[i].fmt, jcr->JobId);
108 return Py_BuildValue(vars[i].fmt, jcr->client_name);
110 return Py_BuildValue(vars[i].fmt, jcr->dcr->pool_name);
111 case 7: /* MediaType */
112 return Py_BuildValue(vars[i].fmt, jcr->dcr->media_type);
113 case 8: /* JobName */
114 return Py_BuildValue(vars[i].fmt, jcr->Job);
115 case 9: /* JobStatus */
117 buf[0] = jcr->JobStatus;
118 return Py_BuildValue(vars[i].fmt, buf);
120 return Py_BuildValue(vars[i].fmt, jcr->dcr->VolumeName);
122 return Py_BuildValue(vars[i].fmt, jcr->dcr->dev_name);
127 /* Set Bacula variables */
128 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw)
133 static char *kwlist[] = {"jcr", "JobReport", NULL};
134 if (!PyArg_ParseTupleAndKeywords(args, keyw, "O|ss:set", kwlist,
138 jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
141 Jmsg(jcr, M_INFO, 0, "%s", msg);
143 return Py_BuildValue("i", 1);
146 #endif /* HAVE_PYTHON */