]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/python.c
First cut Python support
[bacula/bacula] / bacula / src / dird / python.c
1 /*
2  * 
3  * Bacula interface to Python for the Director
4  *
5  * Kern Sibbald, November MMIV
6  *
7  *   Version $Id$
8  *
9  */
10
11 /*
12    
13    Copyright (C) 2004 Kern Sibbald
14
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.
19
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.
24
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,
28    MA 02111-1307, USA.
29
30  */
31
32 #include "bacula.h"
33 #include "dird.h"
34
35 #ifdef HAVE_PYTHON
36 #include <Python.h>
37
38 bool run_module(const char *module);
39
40 PyObject *bacula_get(PyObject *self, PyObject *args);
41 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw);
42
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 */
49 };
50
51
52 /* Return Bacula variables */
53 PyObject *bacula_get(PyObject *self, PyObject *args)
54 {
55    PyObject *CObject;
56    JCR *jcr;
57    char *item;
58    if (!PyArg_ParseTuple(args, "Os:get", &CObject, &item)) {
59       return NULL;
60    }
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);
87    }
88    return NULL;
89 }
90
91 /* Set Bacula variables */
92 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw)
93 {
94    PyObject *CObject;
95    JCR *jcr;
96    char *msg = NULL;
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)) {
101       return NULL;
102    }
103    jcr = (JCR *)PyCObject_AsVoidPtr(CObject);
104    if (msg) {
105       Jmsg(jcr, M_INFO, 0, "%s", msg);
106    }
107    if (VolumeName) {
108       pm_strcpy(jcr->VolumeName, VolumeName);
109    }
110    return Py_BuildValue("i", 1);
111 }
112
113 #endif /* HAVE_PYTHON */