]> git.ipfire.org Git - pakfire.git/commitdiff
_pakfire: Add function to simply open archives
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jul 2021 17:02:47 +0000 (17:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 8 Jul 2021 17:02:47 +0000 (17:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/archive.c
src/_pakfire/archive.h
src/_pakfire/pakfire.c

index 3eda9d8dae0eca51471d93ac33a09462a1e1bd9b..6675eaaf7c3375ede80e910b6d48c09b2de01f6e 100644 (file)
 #include "errors.h"
 #include "package.h"
 
+PyObject* new_archive(PyTypeObject* type, PakfireArchive archive) {
+       ArchiveObject* self = (ArchiveObject *)type->tp_alloc(type, 0);
+       if (self) {
+               self->archive = pakfire_archive_ref(archive);
+       }
+
+       return (PyObject*)self;
+}
+
 static PyObject* Archive_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
        ArchiveObject* self = (ArchiveObject *)type->tp_alloc(type, 0);
        if (self) {
index a750842d235d5086ed04eef46e3c431025fa612a..25e72df0ffffc03ae1577406e5f77db14b17dd16 100644 (file)
@@ -32,4 +32,6 @@ typedef struct {
 
 extern PyTypeObject ArchiveType;
 
+PyObject* new_archive(PyTypeObject* type, PakfireArchive archive);
+
 #endif /* PYTHON_PAKFIRE_ARCHIVE_H */
index 4c83e170037d051829c785489f2e5e4c0f41bae0..8e476b45ca63e6fc8101c58bad18e6ddc5c814ea 100644 (file)
@@ -21,6 +21,7 @@
 #include <Python.h>
 #include <errno.h>
 
+#include <pakfire/archive.h>
 #include <pakfire/build.h>
 #include <pakfire/constants.h>
 #include <pakfire/dist.h>
@@ -34,6 +35,7 @@
 #include <pakfire/request.h>
 #include <pakfire/util.h>
 
+#include "archive.h"
 #include "errors.h"
 #include "key.h"
 #include "pakfire.h"
@@ -975,6 +977,26 @@ static PyObject* Pakfire_sync(PakfireObject* self, PyObject* args, PyObject* kwa
        Py_RETURN_NONE;
 }
 
+static PyObject* Pakfire_open(PakfireObject* self, PyObject* args) {
+       PakfireArchive archive = NULL;
+       const char* path = NULL;
+
+       if (!PyArg_ParseTuple(args, "s", &path))
+               return NULL;
+
+       int r = pakfire_archive_open(&archive, self->pakfire, path);
+       if (r) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               return NULL;
+       }
+
+       // Create Python object
+       PyObject* object = new_archive(&ArchiveType, archive);
+       pakfire_archive_unref(archive);
+
+       return object;
+}
+
 static struct PyMethodDef Pakfire_methods[] = {
        {
                "bind",
@@ -1066,6 +1088,12 @@ static struct PyMethodDef Pakfire_methods[] = {
                METH_VARARGS|METH_KEYWORDS,
                NULL,
        },
+       {
+               "open",
+               (PyCFunction)Pakfire_open,
+               METH_VARARGS,
+               NULL
+       },
        {
                "refresh",
                (PyCFunction)Pakfire_refresh,