3 * Bacula interface to Python for the Director
5 * Kern Sibbald, November MMIV
13 Copyright (C) 2004 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,
38 bool run_module(const char *module);
40 PyObject *bacula_get(PyObject *self, PyObject *args);
41 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw);
43 /* Define Bacula entry points */
44 PyMethodDef BaculaMethods[] = {
45 {"get", bacula_get, METH_VARARGS, "Get Bacula variables."},
46 {"set", (PyCFunction)bacula_set, METH_VARARGS|METH_KEYWORDS,
47 "Set Bacula variables."},
48 {NULL, NULL, 0, NULL} /* last item */
57 static struct s_vars vars[] = {
64 { N_("NumVols"), "i"},
66 { N_("Storage"), "s"},
67 { N_("Catalog"), "s"},
68 { N_("MediaType"), "s"},
69 { N_("JobName"), "s"},
70 { N_("JobStatus"), "s"},
75 /* Return Bacula variables */
76 PyObject *bacula_get(PyObject *self, PyObject *args)
85 if (!PyArg_ParseTuple(args, "Os:get", &CObject, &item)) {
88 jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
89 for (i=0; vars[i].name; i++) {
90 if (strcmp(vars[i].name, item) == 0) {
100 return Py_BuildValue(vars[i].fmt, jcr->job->hdr.name);
101 case 1: /* Director's name */
102 return Py_BuildValue(vars[i].fmt, my_name);
104 return Py_BuildValue(vars[i].fmt, job_level_to_str(jcr->JobLevel));
106 return Py_BuildValue(vars[i].fmt, job_type_to_str(jcr->JobType));
108 return Py_BuildValue(vars[i].fmt, jcr->JobId);
110 return Py_BuildValue(vars[i].fmt, jcr->client->hdr.name);
111 case 6: /* NumVols */
112 return Py_BuildValue(vars[i].fmt, jcr->NumVols);
114 return Py_BuildValue(vars[i].fmt, jcr->pool->hdr.name);
115 case 8: /* Storage */
116 return Py_BuildValue(vars[i].fmt, jcr->store->hdr.name);
118 return Py_BuildValue(vars[i].fmt, jcr->catalog->hdr.name);
119 case 10: /* MediaType */
120 return Py_BuildValue(vars[i].fmt, jcr->store->media_type);
121 case 11: /* JobName */
122 return Py_BuildValue(vars[i].fmt, jcr->Job);
123 case 12: /* JobStatus */
125 buf[0] = jcr->JobStatus;
126 return Py_BuildValue(vars[i].fmt, buf);
131 /* Set Bacula variables */
132 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw)
137 char *VolumeName = NULL;
138 static char *kwlist[] = {"jcr", "JobReport", "VolumeName", NULL};
139 if (!PyArg_ParseTupleAndKeywords(args, keyw, "O|ss:set", kwlist,
140 &CObject, &msg, &VolumeName)) {
143 jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
146 Jmsg(jcr, M_INFO, 0, "%s", msg);
149 pm_strcpy(jcr->VolumeName, VolumeName);
151 return Py_BuildValue("i", 1);
154 #endif /* HAVE_PYTHON */