Skip to content
Snippets Groups Projects
Commit ab303446 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

Added functions configGetItem and configGetItemDefault. They accept a section,...

Added functions configGetItem and configGetItemDefault. They accept a section, a key, and the second function accepts a default value. These functions take parameters as strings and return string. Also added a test for these functions.
parent b7453f87
No related branches found
No related tags found
1 merge request!26Support 3689
......@@ -119,6 +119,29 @@ static PyObject* dap_log_it(PyObject* self, PyObject* args){
return PyLong_FromLong(0);
}
static PyObject* py_m_dap_config_get_item(PyObject *self, PyObject *args){
const char *section_path;
const char *item_name;
if (!PyArg_ParseTuple(args, "s|s", &section_path, &item_name))
return NULL;
const char *res = dap_config_get_item_str(g_config, section_path, item_name);
if (res == NULL){
PyErr_SetString(PyExc_ValueError, "The value could not be obtained. Or there is no section. Or missing key in the section.");
return NULL;
}
return Py_BuildValue("s", res);
}
static PyObject* py_m_dap_config_get_item_default(PyObject *self, PyObject *args){
const char *section_path;
const char *item_name;
const char *def;
if (!PyArg_ParseTuple(args, "s|s|s", &section_path, &item_name, &def))
return NULL;
const char *res = dap_config_get_item_str_default(g_config, section_path, item_name, def);
return Py_BuildValue("s", res);
}
PyMODINIT_FUNC PyInit_libdap_python_module(void){
return PyModule_Create(&dapmodule);
}
......
......@@ -19,11 +19,17 @@ static PyObject* dap_log_it(PyObject* self, PyObject* args);
static dap_log_level_t convert_const_char_to_dap_log_level(const char* string);
static PyObject* py_m_dap_config_get_item(PyObject *self, PyObject *args);
static PyObject* py_m_dap_config_get_item_default(PyObject *self, PyObject *args);
static PyMethodDef DapMethods[] = {
{"init", dap_init, METH_VARARGS, "Initialization of the DAP (Deus Applicaions Prototypes) library"},
{"deinit", dap_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) library"},
{"setLogLevel", dap_set_log_level, METH_VARARGS, "Setting the logging level"},
{"logIt", dap_log_it, METH_VARARGS, "The wrapper of the log_it function for the libdap library"},
{"configGetItem", py_m_dap_config_get_item, METH_VARARGS, ""},
{"configGetItemDefault", py_m_dap_config_get_item_default, METH_VARARGS, ""},
{NULL, NULL, 0, NULL}
};
......
......@@ -26,5 +26,11 @@ class Dap:
res_log_it = libdap_python_module.logIt(parse_data['level']+"\n"+parse_data['data'])
if res_log_it == -1:
raise DapIniException("Could not execute log_it function. Perhaps you did not correctly specify the name of the logging level or did not leave the information that needs to be displayed")
def configGetItem(self, section_path, item_name):
res = libdap_python_module.configGetItem(section_path, item_name)
return res
def configGetItemDefault(self, section_path, item_name, default):
return libdap_python_module.configGetItemDefault(section_path, item_name, default)
......@@ -18,3 +18,8 @@ daptest.logIt("""{
"data": "Test. Outputting a string using the log_it function in the libdap library"
}""")
print("Outputting a string using the log_it function done")
res1 = daptest.configGetItem("server", "listen_address")
print("Output [server] 'listen_address' = "+res1+"\n")
res2 = daptest.configGetItemDefault("server1", "listen_address", "8.8.8.8")
print("Output default value '8.8.8.8' \n [server1] 'listen_address' = "+res2+"\n")
print("TEST. Get default config done")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment