src/_pakfire/key.h \
src/_pakfire/package.c \
src/_pakfire/package.h \
+ src/_pakfire/pakfire.c \
+ src/_pakfire/pakfire.h \
src/_pakfire/pool.c \
src/_pakfire/pool.h \
src/_pakfire/problem.c \
src/libpakfire/key.c \
src/libpakfire/package.c \
src/libpakfire/packagelist.c \
+ src/libpakfire/pakfire.c \
src/libpakfire/pool.c \
src/libpakfire/problem.c \
src/libpakfire/relation.c \
src/libpakfire/include/pakfire/package.h \
src/libpakfire/include/pakfire/packagecache.h \
src/libpakfire/include/pakfire/packagelist.h \
+ src/libpakfire/include/pakfire/pakfire.h \
src/libpakfire/include/pakfire/pool.h \
src/libpakfire/include/pakfire/problem.h \
src/libpakfire/include/pakfire/relation.h \
#include "errors.h"
#include "key.h"
#include "package.h"
+#include "pakfire.h"
#include "pool.h"
#include "problem.h"
#include "relation.h"
Py_INCREF(PyExc_DependencyError);
PyModule_AddObject(module, "DependencyError", PyExc_DependencyError);
+ // Pakfire
+ if (PyType_Ready(&PakfireType) < 0)
+ return NULL;
+
+ Py_INCREF(&PakfireType);
+ PyModule_AddObject(module, "Pakfire", (PyObject *)&PakfireType);
+
// Archive
if (PyType_Ready(&ArchiveType) < 0)
return NULL;
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2017 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/pakfire.h>
+
+#include "pakfire.h"
+
+static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
+ PakfireObject* self = (PakfireObject *)type->tp_alloc(type, 0);
+ if (self) {
+ self->pakfire = NULL;
+ }
+
+ return (PyObject *)self;
+}
+
+static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
+ const char* path = NULL;
+ const char* arch = NULL;
+
+ if (!PyArg_ParseTuple(args, "ss", &path, &arch))
+ return -1;
+
+ self->pakfire = pakfire_create(path, arch);
+ if (!self->pakfire)
+ return -1;
+
+ return 0;
+}
+
+static void Pakfire_dealloc(PakfireObject* self) {
+ if (self->pakfire)
+ pakfire_unref(self->pakfire);
+
+ Py_TYPE(self)->tp_free((PyObject *)self);
+}
+
+static PyObject* Pakfire_repr(PakfireObject* self) {
+ const char* path = pakfire_get_path(self->pakfire);
+ const char* arch = pakfire_get_arch(self->pakfire);
+
+ return PyUnicode_FromFormat("<_pakfire.Pakfire %s (%s)>", path, arch);
+}
+
+static PyObject* Pakfire_get_path(PakfireObject* self) {
+ const char* path = pakfire_get_path(self->pakfire);
+
+ return PyUnicode_FromString(path);
+}
+
+static PyObject* Pakfire_get_arch(PakfireObject* self) {
+ const char* arch = pakfire_get_arch(self->pakfire);
+
+ return PyUnicode_FromString(arch);
+}
+
+static struct PyMethodDef Pakfire_methods[] = {
+ { NULL },
+};
+
+static struct PyGetSetDef Pakfire_getsetters[] = {
+ {
+ "arch",
+ (getter)Pakfire_get_arch,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ "path",
+ (getter)Pakfire_get_path,
+ NULL,
+ NULL,
+ NULL
+ },
+ { NULL },
+};
+
+PyTypeObject PakfireType = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ tp_name: "_pakfire.Pakfire",
+ tp_basicsize: sizeof(PakfireObject),
+ tp_flags: Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+ tp_new: Pakfire_new,
+ tp_dealloc: (destructor)Pakfire_dealloc,
+ tp_init: (initproc)Pakfire_init,
+ tp_doc: "Pakfire object",
+ tp_methods: Pakfire_methods,
+ tp_getset: Pakfire_getsetters,
+ tp_repr: (reprfunc)Pakfire_repr,
+};
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2017 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_PAKFIRE_H
+#define PYTHON_PAKFIRE_PAKFIRE_H
+
+#include <Python.h>
+
+#include <pakfire/pakfire.h>
+
+typedef struct {
+ PyObject_HEAD
+ Pakfire pakfire;
+} PakfireObject;
+
+extern PyTypeObject PakfireType;
+
+#endif /* PYTHON_PAKFIRE_PAKFIRE_H */
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2017 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 PAKFIRE_PAKFIRE_H
+#define PAKFIRE_PAKFIRE_H
+
+#include <pakfire/types.h>
+
+Pakfire pakfire_create(const char* path, const char* arch);
+
+Pakfire pakfire_ref(Pakfire pakfire);
+void pakfire_unref(Pakfire pakfire);
+
+const char* pakfire_get_path(Pakfire pakfire);
+const char* pakfire_get_arch(Pakfire pakfire);
+
+#ifdef PAKFIRE_PRIVATE
+
+struct _Pakfire {
+ char* path;
+ char* arch;
+ int nrefs;
+};
+
+#endif
+
+#endif /* PAKFIRE_PAKFIRE_H */
#ifndef PAKFIRE_TYPES_H
#define PAKFIRE_TYPES_H
+typedef struct _Pakfire* Pakfire;
typedef struct _PakfireArchive* PakfireArchive;
typedef struct _PakfireCache* PakfireCache;
typedef struct _PakfireFile* PakfireFile;
LIBPAKFIRE_0 {
global:
+ # pakfire
+ pakfire_create;
+ pakfire_get_arch;
+ pakfire_get_path;
+ pakfire_ref;
+ pakfire_unref;
+
# archive
pakfire_archive_create;
pakfire_archive_extract;
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2017 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 <pakfire/pakfire.h>
+#include <pakfire/types.h>
+#include <pakfire/util.h>
+
+Pakfire pakfire_create(const char* path, const char* arch) {
+ Pakfire pakfire = pakfire_calloc(1, sizeof(*pakfire));
+ if (pakfire) {
+ pakfire->path = pakfire_strdup(path);
+ pakfire->arch = pakfire_strdup(arch);
+ }
+
+ return pakfire;
+}
+
+Pakfire pakfire_ref(Pakfire pakfire) {
+ ++pakfire->nrefs;
+
+ return pakfire;
+}
+
+void pakfire_unref(Pakfire pakfire) {
+ if (--pakfire->nrefs > 0)
+ return;
+
+ pakfire_free(pakfire->path);
+ pakfire_free(pakfire->arch);
+}
+
+const char* pakfire_get_path(Pakfire pakfire) {
+ return pakfire->path;
+}
+
+const char* pakfire_get_arch(Pakfire pakfire) {
+ return pakfire->arch;
+}
from .constants import *
from .i18n import _
-class Pakfire(object):
+class Pakfire(_pakfire.Pakfire):
__version__ = PAKFIRE_VERSION
mode = None
def __init__(self, path="/", config=None, arch=None, distro=None, cache_path=None):
- # The path where we are operating in
- self.path = path
-
- # Default to system architecture
- self.arch = arch or system.arch
+ _pakfire.Pakfire.__init__(self, path, arch or system.native_arch)
# Default to system distribution
self.distro = distro or system.distro
# Initialize the keyring
#self.keyring = keyring.Keyring(self)
- self.pool = _pakfire.Pool(self.arch.name)
+ self.pool = _pakfire.Pool(self.arch)
self.pool.cache_path = cache_path or \
os.path.join(CACHE_DIR, self.distro.sname, self.distro.release)
import uuid
from . import _pakfire
+from . import arch
from . import base
from . import cgroup
from . import config
# Get a reference to Pakfire
self.pakfire = self.builder.pakfire
+ # Architecture
+ self.arch = arches.Arch(self.pakfire.arch)
+
# Get a reference to the logger
self.log = self.builder.log
# Fake UTS_MACHINE, when we cannot use the personality syscall and
# if the host architecture is not equal to the target architecture.
- if not self.pakfire.arch.personality and \
- not system.native_arch == self.pakfire.arch.name:
+ if not self.arch.personality and \
+ not system.native_arch == self.arch.name:
env.update({
"LD_PRELOAD" : "/usr/lib/libpakfire_preload.so",
- "UTS_MACHINE" : self.pakfire.arch.name,
+ "UTS_MACHINE" : self.arch.name,
})
return env
# Handle variable expansion.
replaces = {
"name" : name,
- "arch" : self.pakfire.arch.name,
+ "arch" : self.pakfire.arch,
}
for k, v in list(_args.items()):
downloader = self.make_downloader()
while True:
- data = downloader.get("%s/repodata/repomd.json" % self.pakfire.arch.name, decode="ascii")
+ data = downloader.get("%s/repodata/repomd.json" % self.pakfire.arch, decode="ascii")
# Parse new metadata for comparison
md = metadata.Metadata(self.pakfire, metadata=data)