]> git.ipfire.org Git - pakfire.git/commitdiff
_pakfire: Create Python abstraction for the build service
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Oct 2023 16:03:03 +0000 (16:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Oct 2023 16:03:03 +0000 (16:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/_pakfire/_pakfiremodule.c
src/_pakfire/buildservice.c [new file with mode: 0644]
src/_pakfire/buildservice.h [new file with mode: 0644]
src/pakfire/buildservice.py [new file with mode: 0644]
src/pakfire/daemon.py

index 1e619a4b22e3eeeaa252f90b738198664ebcfc22..02684fdccc5a3c5734442d609ab481779c278cd2 100644 (file)
@@ -138,6 +138,8 @@ _pakfire_la_SOURCES = \
        src/_pakfire/archive.h \
        src/_pakfire/archive_file.c \
        src/_pakfire/archive_file.h \
+       src/_pakfire/buildservice.c \
+       src/_pakfire/buildservice.h \
        src/_pakfire/errors.h \
        src/_pakfire/file.c \
        src/_pakfire/file.h \
@@ -163,6 +165,7 @@ _pakfire_la_CPPFLAGS = \
 _pakfire_la_CFLAGS = \
        $(AM_CFLAGS) \
        $(PYTHON_DEVEL_CFLAGS) \
+       $(JSON_C_CFLAGS) \
        -Wno-cast-function-type
 
 _pakfire_la_LDFLAGS = \
index 74dd0a9f1df299d3b6d0342972618e161674ca00..c93b6695c3df8f2fbfb034340b52fbc64d1171a2 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "archive.h"
 #include "archive_file.h"
+#include "buildservice.h"
 #include "errors.h"
 #include "file.h"
 #include "key.h"
@@ -326,6 +327,13 @@ PyMODINIT_FUNC PyInit__pakfire(void) {
        Py_INCREF(&ArchiveFileType);
        PyModule_AddObject(module, "ArchiveFile", (PyObject*)&ArchiveFileType);
 
+       // BuildService
+       if (PyType_Ready(&BuildServiceType) < 0)
+               return NULL;
+
+       Py_INCREF(&BuildServiceType);
+       PyModule_AddObject(module, "BuildService", (PyObject*)&BuildServiceType);
+
        // File
        if (PyType_Ready(&FileType) < 0)
                return NULL;
diff --git a/src/_pakfire/buildservice.c b/src/_pakfire/buildservice.c
new file mode 100644 (file)
index 0000000..8357a7b
--- /dev/null
@@ -0,0 +1,112 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <Python.h>
+
+#include <pakfire/ctx.h>
+#include <pakfire/buildservice.h>
+
+#include "buildservice.h"
+
+extern struct pakfire_ctx* pakfire_ctx;
+
+static PyObject* BuildService_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
+       BuildServiceObject* self = (BuildServiceObject *)type->tp_alloc(type, 0);
+       if (self)
+               self->service = NULL;
+
+       return (PyObject *)self;
+}
+
+static int BuildService_init(BuildServiceObject* self, PyObject* args, PyObject* kwds) {
+       int r;
+
+       r = pakfire_buildservice_create(&self->service, pakfire_ctx);
+       if (r) {
+               errno = -r;
+
+               PyErr_SetFromErrno(PyExc_OSError);
+               return -1;
+       }
+
+       return 0;
+}
+
+static void BuildService_dealloc(BuildServiceObject* self) {
+       if (self->service)
+               pakfire_buildservice_unref(self->service);
+
+       Py_TYPE(self)->tp_free((PyObject *)self);
+}
+
+static PyObject* BuildService_upload(BuildServiceObject* self, PyObject* args, PyObject* kwds) {
+       const char* kwlist[] = { "path", "filename", NULL };
+       const char* filename = NULL;
+       const char* path = NULL;
+       PyObject* result = NULL;
+       char* uuid = NULL;
+       int r;
+
+       // Parse arguments
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|z", (char**)kwlist, &path, &filename))
+               return NULL;
+
+       // Perform the upload
+       r = pakfire_buildservice_upload(self->service, path, filename, &uuid);
+       if (r > 0) {
+               // XXX throw some nice exceptions...
+               goto ERROR;
+
+       } else if (r < 0) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               goto ERROR;
+       }
+
+       // Return the UUID
+       result = PyUnicode_FromString(uuid);
+
+ERROR:
+       if (uuid)
+               free(uuid);
+
+       return result;
+}
+
+static struct PyMethodDef BuildService_methods[] = {
+       {
+               "upload",
+               (PyCFunction)BuildService_upload,
+               METH_VARARGS|METH_KEYWORDS,
+               NULL,
+       },
+       { NULL },
+};
+
+PyTypeObject BuildServiceType = {
+       PyVarObject_HEAD_INIT(NULL, 0)
+       tp_name:            "_pakfire.BuildService",
+       tp_basicsize:       sizeof(BuildServiceObject),
+       tp_flags:           Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+       tp_new:             BuildService_new,
+       tp_dealloc:         (destructor)BuildService_dealloc,
+       tp_init:            (initproc)BuildService_init,
+       tp_doc:             "BuildService Object",
+       tp_methods:         BuildService_methods,
+};
diff --git a/src/_pakfire/buildservice.h b/src/_pakfire/buildservice.h
new file mode 100644 (file)
index 0000000..8d728ec
--- /dev/null
@@ -0,0 +1,35 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PYTHON_PAKFIRE_BUILDSERVICE_H
+#define PYTHON_PAKFIRE_BUILDSERVICE_H
+
+#include <Python.h>
+
+#include <pakfire/buildservice.h>
+
+typedef struct {
+       PyObject_HEAD
+       struct pakfire_buildservice* service;
+} BuildServiceObject;
+
+extern PyTypeObject BuildServiceType;
+
+#endif /* PYTHON_PAKFIRE_BUILDSERVICE_H */
diff --git a/src/pakfire/buildservice.py b/src/pakfire/buildservice.py
new file mode 100644 (file)
index 0000000..961bb37
--- /dev/null
@@ -0,0 +1,28 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import _pakfire
+
+class BuildService(_pakfire.BuildService):
+       """
+               This wraps the parts of the build service
+               that has been implemented in libpakfire.
+       """
+       pass
index 8412fad5ebcc9b159833e47a943893478e2e92d0..d32bf89b3833f6ecfce5cc687392298bd932e576 100644 (file)
@@ -15,6 +15,7 @@ import socket
 import tempfile
 
 from . import _pakfire
+from . import buildservice
 from . import config
 from . import hub
 from . import logger
@@ -31,6 +32,9 @@ class Daemon(object):
                self.debug   = debug
                self.verbose = verbose
 
+               # Initialize the connection to the buildservice
+               self.buildservice = buildservice.BuildService()
+
                # Setup logger
                self.log = logger.setup(
                        "pakfire",