+++ /dev/null
-/*#############################################################################
-# #
-# 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,
-};
+++ /dev/null
-/*#############################################################################
-# #
-# 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 */