]> git.ipfire.org Git - pakfire.git/commitdiff
_pakfire: Drop the old Python logging callback
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Oct 2023 10:37:27 +0000 (10:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Oct 2023 10:37:27 +0000 (10:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/_pakfire/pakfire.h

index 74d82ce2887a3567cc839dd56b4b7982c899e3c1..27df756101f5a2f532213760cf597f5c9771d510 100644 (file)
@@ -56,85 +56,6 @@ static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
        return (PyObject *)self;
 }
 
-static void Pakfire_log_callback(void* data, int priority, const char* file, int line,
-               const char* fn, const char* format, va_list args) {
-       PyObject* callback = (PyObject*)data;
-       PyObject* exception = NULL;
-       PyObject* type = NULL;
-       PyObject* value = NULL;
-       PyObject* traceback = NULL;
-
-       // Do nothing if callback isn't set
-       if (!callback)
-               return;
-
-       PyGILState_STATE state = PyGILState_Ensure();
-
-       // Translate priority to Python logging priorities
-       switch (priority) {
-               case LOG_DEBUG:
-                       priority = 10;
-                       break;
-
-               case LOG_INFO:
-                       priority = 20;
-                       break;
-
-               case LOG_ERR:
-                       priority = 40;
-                       break;
-
-               // Drop messages of an unknown priority
-               default:
-                       return;
-       }
-
-       PyObject* tuple = NULL;
-       PyObject* result = NULL;
-       char* buffer = NULL;
-
-       // Make line
-       int r = vasprintf(&buffer, format, args);
-       if (r < 0)
-               goto ERROR;
-
-       // Build a tuple with the priority and the log message
-       tuple = Py_BuildValue("(is)", priority, buffer);
-       if (!tuple)
-               goto ERROR;
-
-       // Call the callback
-       result = PyObject_CallObject(callback, tuple);
-
-ERROR:
-       /*
-               We cannot really catch any Python errors here, since we cannot send
-               any error codes up the chain.
-
-               So, in order to debug the problem, We will check if an exception has
-               occurred and if so, print it to the console.
-       */
-       exception = PyErr_Occurred();
-       if (exception) {
-               PyErr_Print();
-
-               // Fetch the exception and destroy it
-               PyErr_Fetch(&type, &value, &traceback);
-
-               Py_XDECREF(type);
-               Py_XDECREF(value);
-               Py_XDECREF(traceback);
-       }
-
-       if (buffer)
-               free(buffer);
-       Py_XDECREF(tuple);
-       Py_XDECREF(result);
-
-       // Release the GIL
-       PyGILState_Release(state);
-}
-
 static int Pakfire_confirm_callback(struct pakfire* pakfire, void* data,
                const char* message, const char* question) {
        PyObject* callback = (PyObject*)data;
@@ -197,16 +118,10 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
 
        FILE* fconf = NULL;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOpOO", kwlist,
-                       &path, &arch, &self->callbacks.log, &offline, &conf, &self->callbacks.confirm))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzpOO", kwlist,
+                       &path, &arch, &offline, &conf, &self->callbacks.confirm))
                goto ERROR;
 
-       // Check if log callback is callable
-       if (self->callbacks.log && !PyCallable_Check(self->callbacks.log)) {
-               PyErr_SetString(PyExc_TypeError, "logger must be callable\n");
-               goto ERROR;
-       }
-
        // Check if confirm callback is callable
        if (self->callbacks.confirm && !PyCallable_Check(self->callbacks.confirm)) {
                PyErr_SetString(PyExc_TypeError, "Confirm callback is not callable");
@@ -226,10 +141,6 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
        if (offline)
                flags |= PAKFIRE_FLAGS_OFFLINE;
 
-       // Configure callbacks
-       if (self->callbacks.log)
-               Py_INCREF(self->callbacks.log);
-
        Py_BEGIN_ALLOW_THREADS
 
        // Create a new Pakfire instance
index 5a37fabe0c9ace655dc719b4e27b23152ce09b03..5927e6aae3316bce1111f96d737be41920964cdd 100644 (file)
@@ -31,7 +31,6 @@ typedef struct {
 
        // Callbacks
        struct callbacks {
-               PyObject* log;
                PyObject* confirm;
        } callbacks;
 } PakfireObject;