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 */
52 /* Return Bacula variables */
53 PyObject *bacula_get(PyObject *self, PyObject *args)
58 if (!PyArg_ParseTuple(args, "Os:get", &CObject, &item)) {
61 jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
62 /* ***FIXME*** put this in a table */
63 if (strcmp(item, "JobId") == 0) {
64 return Py_BuildValue("i", jcr->JobId);
65 } else if (strcmp(item, "Client") == 0) {
66 return Py_BuildValue("s", jcr->client->hdr.name);
67 } else if (strcmp(item, "Pool") == 0) {
68 return Py_BuildValue("s", jcr->pool->hdr.name);
69 } else if (strcmp(item, "Storage") == 0) {
70 return Py_BuildValue("s", jcr->store->hdr.name);
71 } else if (strcmp(item, "Catalog") == 0) {
72 return Py_BuildValue("s", jcr->catalog->hdr.name);
73 } else if (strcmp(item, "MediaType") == 0) {
74 return Py_BuildValue("s", jcr->store->media_type);
75 } else if (strcmp(item, "NumVols") == 0) {
76 return Py_BuildValue("i", jcr->NumVols);
77 } else if (strcmp(item, "DirName") == 0) {
78 return Py_BuildValue("s", my_name);
79 } else if (strcmp(item, "Level") == 0) {
80 return Py_BuildValue("s", job_level_to_str(jcr->JobLevel));
81 } else if (strcmp(item, "Type") == 0) {
82 return Py_BuildValue("s", job_type_to_str(jcr->JobType));
83 } else if (strcmp(item, "Job") == 0) {
84 return Py_BuildValue("s", jcr->job->hdr.name);
85 } else if (strcmp(item, "JobName") == 0) {
86 return Py_BuildValue("s", jcr->Job);
91 /* Set Bacula variables */
92 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw)
97 char *VolumeName = NULL;
98 static char *kwlist[] = {"jcr", "JobReport", "VolumeName", NULL};
99 if (!PyArg_ParseTupleAndKeywords(args, keyw, "O|ss:set", kwlist,
100 &CObject, &msg, &VolumeName)) {
103 jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
105 Jmsg(jcr, M_INFO, 0, "%s", msg);
108 pm_strcpy(jcr->VolumeName, VolumeName);
110 return Py_BuildValue("i", 1);
113 #endif /* HAVE_PYTHON */