]> git.ipfire.org Git - pakfire.git/commitdiff
python: Remove the build service implementation wrapper
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 5 Oct 2024 14:32:08 +0000 (14:32 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 5 Oct 2024 14:32:08 +0000 (14:32 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/_pakfire/_pakfiremodule.c
src/_pakfire/buildservice.c [deleted file]
src/_pakfire/buildservice.h [deleted file]

index df1386edbdacd1eb9e8e8f481d808f632afb4b2e..fab9f4e8af3c731854960f5f59352a53626222fb 100644 (file)
@@ -125,8 +125,6 @@ _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/ctx.c \
        src/_pakfire/ctx.h \
        src/_pakfire/errors.h \
index e28595a14d49e47508e741e9625f3c68d06b0c16..69421588bfc31a3df1bf94c5831e5530b7ee0134 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "archive.h"
 #include "archive_file.h"
-#include "buildservice.h"
 #include "ctx.h"
 #include "errors.h"
 #include "file.h"
@@ -191,13 +190,6 @@ 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);
-
        // Ctx
        if (PyType_Ready(&CtxType) < 0)
                return NULL;
diff --git a/src/_pakfire/buildservice.c b/src/_pakfire/buildservice.c
deleted file mode 100644 (file)
index 9ca5eec..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-/*#############################################################################
-#                                                                             #
-# 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"
-#include "ctx.h"
-
-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) {
-       CtxObject* ctx = NULL;
-       int r;
-
-       if (!PyArg_ParseTuple(args, "O!", &CtxType, &ctx))
-               return -1;
-
-       r = pakfire_buildservice_create(&self->service, ctx->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_get_url(BuildServiceObject* self) {
-       const char* url = NULL;
-
-       // Fetch the URL
-       url = pakfire_buildservice_get_url(self->service);
-       if (!url) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       return PyUnicode_FromString(url);
-}
-
-static int convert_packages(PyObject* object, void* data) {
-       char*** packages = data;
-
-       // Called for cleanup
-       if (!object)
-               goto ERROR;
-
-       // Nothing to do when object is None
-       if (object == Py_None)
-               return Py_CLEANUP_SUPPORTED;
-
-       if (!PySequence_Check(object)) {
-               PyErr_SetString(PyExc_ValueError, "packages must be a sequence");
-               goto ERROR;
-       }
-
-       const unsigned int length = PySequence_Length(object);
-       if (!length)
-               return Py_CLEANUP_SUPPORTED;
-
-       // Allocate array
-       *packages = calloc(length + 1, sizeof(*packages));
-       if (!*packages) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               goto ERROR;
-       }
-
-       for (unsigned int i = 0; i < length; i++) {
-               PyObject* item = PySequence_GetItem(object, i);
-
-               // Check if input is a string
-               if (!PyUnicode_Check(item)) {
-                       Py_DECREF(item);
-
-                       PyErr_SetString(PyExc_AttributeError, "Expected a string");
-                       goto ERROR;
-               }
-
-               // Fetch string
-               const char* package = PyUnicode_AsUTF8(item);
-               if (!package) {
-                       Py_DECREF(item);
-                       goto ERROR;
-               }
-
-               // Add package to array
-               (*packages)[i] = strdup(package);
-               if (!(*packages)[i]) {
-                       Py_DECREF(item);
-                       goto ERROR;
-               }
-
-               Py_DECREF(item);
-       }
-
-       // Success
-       return Py_CLEANUP_SUPPORTED;
-
-ERROR:
-       if (*packages) {
-               for (char** package = *packages; *package; package++)
-                       free(*package);
-               free(*packages);
-       }
-
-       return 0;
-}
-
-static PyObject* BuildService_job_finished(BuildServiceObject* self, PyObject* args, PyObject* kwargs) {
-       char* kwlist[] = { "uuid", "success", "logfile", "packages", NULL };
-       const char* uuid = NULL;
-       int success = 0;
-       const char* logfile = NULL;
-       char** packages = NULL;
-       int r;
-
-       // Parse arguments
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sp|zO&", kwlist, &uuid, &success,
-                       &logfile, convert_packages, &packages))
-               return NULL;
-
-       // Send request
-       r = pakfire_buildservice_job_finished(self->service, uuid, success,
-               logfile, (const char**)packages);
-       if (r)
-               goto ERROR;
-
-ERROR:
-       if (packages) {
-               for (char** package = packages; *package; package++)
-                       free(*package);
-               free(packages);
-       }
-
-       if (r)
-               return NULL;
-
-       Py_RETURN_NONE;
-}
-
-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[] = {
-       {
-               "job_finished",
-               (PyCFunction)BuildService_job_finished,
-               METH_VARARGS|METH_KEYWORDS,
-               NULL,
-       },
-       {
-               "upload",
-               (PyCFunction)BuildService_upload,
-               METH_VARARGS|METH_KEYWORDS,
-               NULL,
-       },
-       { NULL },
-};
-
-static struct PyGetSetDef BuildService_getsetters[] = {
-       {
-               "url",
-               (getter)BuildService_get_url,
-               NULL,
-               NULL,
-               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,
-       tp_getset:          BuildService_getsetters,
-};
diff --git a/src/_pakfire/buildservice.h b/src/_pakfire/buildservice.h
deleted file mode 100644 (file)
index 8d728ec..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*#############################################################################
-#                                                                             #
-# 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 */