diff --git a/src/libdap-python.c b/src/libdap-python.c index 79bb87ebae28dc1c0580e32a75f8a79ce60434f6..ffe602cdba7544a833d7f114576ad49c8a705d1f 100644 --- a/src/libdap-python.c +++ b/src/libdap-python.c @@ -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", §ion_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", §ion_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); } diff --git a/src/libdap-python.h b/src/libdap-python.h index f43a70d79bc48e1357c94fc849c27a3ae851474c..1aac3c6ab27878ef1aec09acc26d47431d35ef9f 100644 --- a/src/libdap-python.h +++ b/src/libdap-python.h @@ -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} }; diff --git a/src/libdapConnector.py b/src/libdapConnector.py index ddcd081a3e7cda40a21564afb92cd0d0cb2a4d9c..a548b9c84de9c29ff1c89caff6a0d091a2f1dcd5 100644 --- a/src/libdapConnector.py +++ b/src/libdapConnector.py @@ -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) + diff --git a/test/main_test.py b/test/main_test.py index 7fbb113e94c03371acf3a12b555fa07b4d9a8987..a76e15a26b775b2294110191d90966201bf99005 100644 --- a/test/main_test.py +++ b/test/main_test.py @@ -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")