|
Packit |
8ea169 |
/*
|
|
Packit |
8ea169 |
Copyright (C) 2010 Abrt team.
|
|
Packit |
8ea169 |
Copyright (C) 2010 RedHat inc.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
8ea169 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
8ea169 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
8ea169 |
(at your option) any later version.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
8ea169 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8ea169 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
8ea169 |
GNU General Public License for more details.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
You should have received a copy of the GNU General Public License along
|
|
Packit |
8ea169 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
8ea169 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
8ea169 |
*/
|
|
Packit |
8ea169 |
#include <Python.h>
|
|
Packit |
8ea169 |
#include "libabrt.h"
|
|
Packit |
8ea169 |
#include "problem_data.h"
|
|
Packit |
8ea169 |
#include "common.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* C: void notify_new_path(const char *path); */
|
|
Packit |
8ea169 |
PyObject *p_notify_new_path(PyObject *pself, PyObject *args)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
const char *path;
|
|
Packit |
8ea169 |
if (!PyArg_ParseTuple(args, "s", &path))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
return NULL;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
notify_new_path(path);
|
|
Packit |
8ea169 |
Py_RETURN_NONE;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
static PyObject *
|
|
Packit |
8ea169 |
load_settings_to_dict(const char *file, int (*loader)(const char *, map_string_t *))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
PyObject *dict = NULL;
|
|
Packit |
8ea169 |
map_string_t *settings = new_map_string();
|
|
Packit |
8ea169 |
if (!loader(file, settings))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
PyErr_SetString(PyExc_OSError, "Failed to load configuration file.");
|
|
Packit |
8ea169 |
goto lacf_error;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
dict = PyDict_New();
|
|
Packit |
8ea169 |
if (dict == NULL)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
goto lacf_error;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
map_string_iter_t iter;
|
|
Packit |
8ea169 |
const char *key = NULL;
|
|
Packit |
8ea169 |
const char *value = NULL;
|
|
Packit |
8ea169 |
init_map_string_iter(&iter, settings);
|
|
Packit |
8ea169 |
while(next_map_string_iter(&iter, &key, &value))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
if (0 != PyDict_SetItemString(dict, key, PyUnicode_FromString(value)))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
goto lacf_error;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
free_map_string(settings);
|
|
Packit |
8ea169 |
return dict;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
lacf_error:
|
|
Packit |
8ea169 |
Py_XDECREF(dict);
|
|
Packit |
8ea169 |
free_map_string(settings);
|
|
Packit |
8ea169 |
return NULL;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* C: void load_abrt_conf_file(const char *file, map_string_t *settings); */
|
|
Packit |
8ea169 |
PyObject *p_load_conf_file(PyObject *pself, PyObject *args)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
const char *file;
|
|
Packit |
8ea169 |
if (!PyArg_ParseTuple(args, "s", &file))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
return NULL;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
return load_settings_to_dict(file, load_abrt_conf_file);
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* C: void load_abrt_plugin_conf_file(const char *file, map_string_t *settings); */
|
|
Packit |
8ea169 |
PyObject *p_load_plugin_conf_file(PyObject *pself, PyObject *args)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
const char *file;
|
|
Packit |
8ea169 |
if (!PyArg_ParseTuple(args, "s", &file))
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
return NULL;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
return load_settings_to_dict(file, load_abrt_plugin_conf_file);
|
|
Packit |
8ea169 |
}
|