--- /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 "ctx.h"
+
+static PyObject* Ctx_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
+ CtxObject* self = (CtxObject *)type->tp_alloc(type, 0);
+ if (self)
+ self->ctx = NULL;
+
+ return (PyObject *)self;
+}
+
+static int Ctx_init(CtxObject* self, PyObject* args, PyObject* kwargs) {
+ char* kwlist[] = { (char*)"path", NULL };
+ const char* path = NULL;
+ int r;
+
+ // Parse arguments
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &path))
+ return -1;
+
+ // Create context
+ r = pakfire_ctx_create(&self->ctx, path);
+ if (r) {
+ errno = -r;
+
+ PyErr_SetFromErrno(PyExc_OSError);
+ return -1;
+ }
+
+ return 0;
+}
+
+static void Ctx_dealloc(CtxObject* self) {
+ if (self->ctx)
+ pakfire_ctx_unref(self->ctx);
+
+ Py_TYPE(self)->tp_free((PyObject *)self);
+}
+
+static struct PyMethodDef Ctx_methods[] = {
+ { NULL },
+};
+
+static struct PyGetSetDef Ctx_getsetters[] = {
+ { NULL },
+};
+
+PyTypeObject CtxType = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ tp_name: "_pakfire.Ctx",
+ tp_basicsize: sizeof(CtxObject),
+ tp_flags: Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+ tp_new: Ctx_new,
+ tp_dealloc: (destructor)Ctx_dealloc,
+ tp_init: (initproc)Ctx_init,
+ tp_doc: "Ctx Object",
+ tp_methods: Ctx_methods,
+ tp_getset: Ctx_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_CTX_H
+#define PYTHON_PAKFIRE_CTX_H
+
+#include <Python.h>
+
+#include <pakfire/ctx.h>
+
+typedef struct {
+ PyObject_HEAD
+ struct pakfire_ctx* ctx;
+} CtxObject;
+
+extern PyTypeObject CtxType;
+
+#endif /* PYTHON_PAKFIRE_CTX_H */