Commit 786f2bbc authored by Karel Koci's avatar Karel Koci 🤘

Add get_all for getting whole section

parent 52826924
Pipeline #34359 passed with stage
in 45 seconds
...@@ -137,8 +137,7 @@ static bool lookup_ptr(uci_object *self, PyObject *args, struct uci_ptr *ptr) { ...@@ -137,8 +137,7 @@ static bool lookup_ptr(uci_object *self, PyObject *args, struct uci_ptr *ptr) {
return true; return true;
} }
static PyObject *pyuci_get(uci_object *self, PyObject *args) { static PyObject *pyuci_get_common(uci_object *self, PyObject *args, bool all) {
// TODO add support for listing all (see section type)
struct uci_ptr ptr; struct uci_ptr ptr;
if (!lookup_ptr(self, args, &ptr)) if (!lookup_ptr(self, args, &ptr))
...@@ -154,8 +153,10 @@ static PyObject *pyuci_get(uci_object *self, PyObject *args) { ...@@ -154,8 +153,10 @@ static PyObject *pyuci_get(uci_object *self, PyObject *args) {
case UCI_TYPE_PACKAGE: case UCI_TYPE_PACKAGE:
return pyuci_package(ptr.p); return pyuci_package(ptr.p);
case UCI_TYPE_SECTION: case UCI_TYPE_SECTION:
// TODO for all push section from ptr.s if (all)
return Py_BuildValue("s", ptr.s->type); return pyuci_section(ptr.s);
else
return Py_BuildValue("s", ptr.s->type);
case UCI_TYPE_OPTION: case UCI_TYPE_OPTION:
return pyuci_option(ptr.o); return pyuci_option(ptr.o);
default: default:
...@@ -168,6 +169,14 @@ static PyObject *pyuci_get(uci_object *self, PyObject *args) { ...@@ -168,6 +169,14 @@ static PyObject *pyuci_get(uci_object *self, PyObject *args) {
} }
} }
static PyObject *pyuci_get(uci_object *self, PyObject *args) {
return pyuci_get_common(self, args, false);
}
static PyObject *pyuci_get_all(uci_object *self, PyObject *args) {
return pyuci_get_common(self, args, true);
}
static PyObject *pyuci_set(uci_object *self, PyObject *args) { static PyObject *pyuci_set(uci_object *self, PyObject *args) {
struct uci_ptr ptr; struct uci_ptr ptr;
memset(&ptr, 0, sizeof ptr); memset(&ptr, 0, sizeof ptr);
...@@ -396,6 +405,7 @@ static PyObject *pyuci_set_savedir(uci_object *self, PyObject *args) { ...@@ -396,6 +405,7 @@ static PyObject *pyuci_set_savedir(uci_object *self, PyObject *args) {
static PyMethodDef uci_methods[] = { static PyMethodDef uci_methods[] = {
{"get", (PyCFunction)pyuci_get, METH_VARARGS, "Get value"}, {"get", (PyCFunction)pyuci_get, METH_VARARGS, "Get value"},
{"get_all", (PyCFunction)pyuci_get_all, METH_VARARGS, "Get all values even for sections"},
{"set", (PyCFunction)pyuci_set, METH_VARARGS, "Set value"}, {"set", (PyCFunction)pyuci_set, METH_VARARGS, "Set value"},
{"delete", (PyCFunction)pyuci_delete, METH_VARARGS, "Delete option"}, {"delete", (PyCFunction)pyuci_delete, METH_VARARGS, "Delete option"},
{"add", (PyCFunction)pyuci_add, METH_VARARGS, "Add new anonymous section"}, {"add", (PyCFunction)pyuci_add, METH_VARARGS, "Add new anonymous section"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment