summaryrefslogtreecommitdiff
path: root/lib/command_py.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2024-07-20 16:19:29 -0700
committerDonald Sharp <sharpd@nvidia.com>2024-07-31 08:08:53 -0400
commit3c1556f386a6c5866e1b5352571e44ed3e22da76 (patch)
tree27739a9fd5470e0585116c823ac18b2676c0a6c8 /lib/command_py.c
parent8511f39987e1ee3438d7ff836e7edf7f619667d8 (diff)
lib/clippy: expose graph nodes' back pointers
There's a wrapper for nodes' outgoing pointers, but not incoming yet. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/command_py.c')
-rw-r--r--lib/command_py.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/command_py.c b/lib/command_py.c
index 6c051f55cd..411caa52d6 100644
--- a/lib/command_py.c
+++ b/lib/command_py.c
@@ -109,6 +109,24 @@ static PyObject *graph_node_next(PyObject *self, PyObject *args)
pylist = PyList_New(vector_active(wrap->node->to));
for (size_t i = 0; i < vector_active(wrap->node->to); i++) {
struct graph_node *gn = vector_slot(wrap->node->to, i);
+
+ PyList_SetItem(pylist, i, graph_to_pyobj(wrap->wgraph, gn));
+ }
+ return pylist;
+};
+
+static PyObject *graph_node_prev(PyObject *self, PyObject *args)
+{
+ struct wrap_graph_node *wrap = (struct wrap_graph_node *)self;
+ PyObject *pylist;
+
+ if (wrap->node->data &&
+ ((struct cmd_token *)wrap->node->data)->type == START_TKN)
+ return PyList_New(0);
+ pylist = PyList_New(vector_active(wrap->node->from));
+ for (size_t i = 0; i < vector_active(wrap->node->from); i++) {
+ struct graph_node *gn = vector_slot(wrap->node->from, i);
+
PyList_SetItem(pylist, i, graph_to_pyobj(wrap->wgraph, gn));
}
return pylist;
@@ -133,9 +151,11 @@ static PyObject *graph_node_join(PyObject *self, PyObject *args)
};
static PyMethodDef methods_graph_node[] = {
- {"next", graph_node_next, METH_NOARGS, "outbound graph edge list"},
- {"join", graph_node_join, METH_NOARGS, "outbound join node"},
- {}};
+ { "next", graph_node_next, METH_NOARGS, "outbound graph edge list" },
+ { "prev", graph_node_prev, METH_NOARGS, "inbound graph edge list" },
+ { "join", graph_node_join, METH_NOARGS, "outbound join node" },
+ {}
+};
static void graph_node_wrap_free(void *arg)
{