]> git.ipfire.org Git - location/libloc.git/commitdiff
python: Implement adding networks to Writer
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jan 2018 16:59:30 +0000 (16:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jan 2018 16:59:30 +0000 (16:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/writer.c

index f7bcb6267ee6329dda1fa5603bcece8785bb1210..9a37b0ee6247df0d8de6f61f9a15765f7c676ef4 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "locationmodule.h"
 #include "as.h"
+#include "network.h"
 #include "writer.h"
 
 static PyObject* Writer_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
@@ -99,6 +100,24 @@ static PyObject* Writer_add_as(WriterObject* self, PyObject* args) {
        return obj;
 }
 
+static PyObject* Writer_add_network(WriterObject* self, PyObject* args) {
+       struct loc_network* network;
+       const char* string = NULL;
+
+       if (!PyArg_ParseTuple(args, "s", &string))
+               return NULL;
+
+       // Create network object
+       int r = loc_writer_add_network(self->writer, &network, string);
+       if (r)
+               return NULL;
+
+       PyObject* obj = new_network(&NetworkType, network);
+       loc_network_unref(network);
+
+       return obj;
+}
+
 static PyObject* Writer_write(WriterObject* self, PyObject* args) {
        const char* path = NULL;
 
@@ -130,6 +149,12 @@ static struct PyMethodDef Writer_methods[] = {
                METH_VARARGS,
                NULL,
        },
+       {
+               "add_network",
+               (PyCFunction)Writer_add_network,
+               METH_VARARGS,
+               NULL,
+       },
        {
                "write",
                (PyCFunction)Writer_write,