From: Michael Tremer Date: Fri, 27 Oct 2023 16:03:03 +0000 (+0000) Subject: _pakfire: Create Python abstraction for the build service X-Git-Tag: 0.9.30~1391 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6111824c4580951e0a6ff01f480969f867383fd;p=pakfire.git _pakfire: Create Python abstraction for the build service Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 1e619a4b2..02684fdcc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 = \ diff --git a/src/_pakfire/_pakfiremodule.c b/src/_pakfire/_pakfiremodule.c index 74dd0a9f1..c93b6695c 100644 --- a/src/_pakfire/_pakfiremodule.c +++ b/src/_pakfire/_pakfiremodule.c @@ -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 index 000000000..8357a7b5e --- /dev/null +++ b/src/_pakfire/buildservice.c @@ -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 . # +# # +#############################################################################*/ + +#include + +#include +#include + +#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 index 000000000..8d728ec2d --- /dev/null +++ b/src/_pakfire/buildservice.h @@ -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 . # +# # +#############################################################################*/ + +#ifndef PYTHON_PAKFIRE_BUILDSERVICE_H +#define PYTHON_PAKFIRE_BUILDSERVICE_H + +#include + +#include + +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 index 000000000..961bb37e7 --- /dev/null +++ b/src/pakfire/buildservice.py @@ -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 . # +# # +############################################################################### + +import _pakfire + +class BuildService(_pakfire.BuildService): + """ + This wraps the parts of the build service + that has been implemented in libpakfire. + """ + pass diff --git a/src/pakfire/daemon.py b/src/pakfire/daemon.py index 8412fad5e..d32bf89b3 100644 --- a/src/pakfire/daemon.py +++ b/src/pakfire/daemon.py @@ -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",