]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/python.c
- Remove Created new FileSet message as it always comes out in
[bacula/bacula] / bacula / src / stored / python.c
1 /*
2  *
3  * Bacula interface to Python for the Storage Daemon
4  *
5  * Kern Sibbald, January MMV
6  *
7  *   Version $Id$
8  *
9  */
10
11 /*
12    Copyright (C) 2005 Kern Sibbald
13
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.
18
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.
23
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,
27    MA 02111-1307, USA.
28
29  */
30
31 #include "bacula.h"
32 #include "stored.h"
33
34 #ifdef HAVE_PYTHON
35 #undef _POSIX_C_SOURCE
36 #include <Python.h>
37
38 extern JCR *get_jcr_from_PyObject(PyObject *self);
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 struct s_vars {
53    const char *name;
54    char *fmt;
55 };
56
57 static struct s_vars vars[] = {
58    { N_("Job"),        "s"},          /* 0 */
59    { N_("SDName"),     "s"},          /* 1 */
60    { N_("Level"),      "s"},          /* 2 */
61    { N_("Type"),       "s"},          /* 3 */
62    { N_("JobId"),      "i"},          /* 4 */
63    { N_("Client"),     "s"},          /* 5 */
64    { N_("Pool"),       "s"},          /* 6 */
65    { N_("MediaType"),  "s"},          /* 7 */
66    { N_("JobName"),    "s"},          /* 8 */
67    { N_("JobStatus"),  "s"},          /* 9 */
68    { N_("VolumeName"), "s"},          /* 10 */
69    { N_("Device"),     "s"},          /* 11 */
70
71    { NULL,             NULL}
72 };
73
74 /* Return Bacula variables */
75 PyObject *bacula_get(PyObject *self, PyObject *args)
76 {
77    JCR *jcr;
78    char *item;
79    bool found = false;
80    int i;
81    char buf[10];
82    
83    if (!PyArg_ParseTuple(args, "s:get", &item)) {
84       return NULL;
85    }
86    jcr = get_jcr_from_PyObject(self);
87
88    for (i=0; vars[i].name; i++) {
89       if (strcmp(vars[i].name, item) == 0) {
90          found = true;
91          break;
92       }
93    }
94    if (!found) {
95       return NULL;
96    }
97    switch (i) {
98    case 0:                            /* Job */
99       return Py_BuildValue(vars[i].fmt, jcr->job_name);    /* Non-unique name */
100    case 1:                            /* SD's name */
101       return Py_BuildValue(vars[i].fmt, my_name);
102    case 2:                            /* level */
103       return Py_BuildValue(vars[i].fmt, job_level_to_str(jcr->JobLevel));
104    case 3:                            /* type */
105       return Py_BuildValue(vars[i].fmt, job_type_to_str(jcr->JobType));
106    case 4:                            /* JobId */
107       return Py_BuildValue(vars[i].fmt, jcr->JobId);
108    case 5:                            /* Client */
109       return Py_BuildValue(vars[i].fmt, jcr->client_name);
110    case 6:                            /* Pool */
111       return Py_BuildValue(vars[i].fmt, jcr->dcr->pool_name);
112    case 7:                            /* MediaType */
113       return Py_BuildValue(vars[i].fmt, jcr->dcr->media_type);
114    case 8:                            /* JobName */
115       return Py_BuildValue(vars[i].fmt, jcr->Job);
116    case 9:                            /* JobStatus */
117       buf[1] = 0;
118       buf[0] = jcr->JobStatus;
119       return Py_BuildValue(vars[i].fmt, buf);
120    case 10:
121       return Py_BuildValue(vars[i].fmt, jcr->dcr->VolumeName);
122    case 11:
123       return Py_BuildValue(vars[i].fmt, jcr->dcr->dev_name);
124    }
125    return NULL;
126 }
127
128 /* Set Bacula variables */
129 PyObject *bacula_set(PyObject *self, PyObject *args, PyObject *keyw)
130 {
131    JCR *jcr;
132    char *msg = NULL;
133    static char *kwlist[] = {"JobReport", NULL};
134    
135    if (!PyArg_ParseTupleAndKeywords(args, keyw, "|s:set", kwlist,
136         &msg)) {
137       return NULL;
138    }
139    jcr = get_jcr_from_PyObject(self);
140
141    if (msg) {
142       Jmsg(jcr, M_INFO, 0, "%s", msg);
143    }
144    return Py_BuildValue("i", 1);
145 }
146
147 #endif /* HAVE_PYTHON */