]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Create a Pakfire root object
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Nov 2017 17:07:04 +0000 (18:07 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Nov 2017 17:07:04 +0000 (18:07 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
12 files changed:
Makefile.am
src/_pakfire/_pakfiremodule.c
src/_pakfire/pakfire.c [new file with mode: 0644]
src/_pakfire/pakfire.h [new file with mode: 0644]
src/libpakfire/include/pakfire/pakfire.h [new file with mode: 0644]
src/libpakfire/include/pakfire/types.h
src/libpakfire/libpakfire.sym
src/libpakfire/pakfire.c [new file with mode: 0644]
src/pakfire/base.py
src/pakfire/builder.py
src/pakfire/repository/__init__.py
src/pakfire/repository/remote.py

index e4168bc2517f107d0d4c532eb46e9e706d007ca6..62f59760e05a6296a10493436bf4e770471471b3 100644 (file)
@@ -185,6 +185,8 @@ _pakfire_la_SOURCES = \
        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 \
@@ -241,6 +243,7 @@ libpakfire_la_SOURCES = \
        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 \
@@ -267,6 +270,7 @@ pkginclude_HEADERS += \
        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 \
index c226407a17c4a4937274b0dc1ccef4533b77b2f0..617cd0b16b136824ad438d01f8d0b09f5afbbb35 100644 (file)
@@ -31,6 +31,7 @@
 #include "errors.h"
 #include "key.h"
 #include "package.h"
+#include "pakfire.h"
 #include "pool.h"
 #include "problem.h"
 #include "relation.h"
@@ -123,6 +124,13 @@ PyMODINIT_FUNC PyInit__pakfire(void) {
        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;
diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c
new file mode 100644 (file)
index 0000000..b3d907c
--- /dev/null
@@ -0,0 +1,110 @@
+/*#############################################################################
+#                                                                             #
+# 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,
+};
diff --git a/src/_pakfire/pakfire.h b/src/_pakfire/pakfire.h
new file mode 100644 (file)
index 0000000..c8f0018
--- /dev/null
@@ -0,0 +1,35 @@
+/*#############################################################################
+#                                                                             #
+# 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 */
diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h
new file mode 100644 (file)
index 0000000..ce81b3f
--- /dev/null
@@ -0,0 +1,44 @@
+/*#############################################################################
+#                                                                             #
+# 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 */
index feb69e2c36fe7bcb3c29fee0548af9d6df22f84f..300b8567b0ac2909d04605addb456ea1e3419c4d 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef PAKFIRE_TYPES_H
 #define PAKFIRE_TYPES_H
 
+typedef struct _Pakfire* Pakfire;
 typedef struct _PakfireArchive* PakfireArchive;
 typedef struct _PakfireCache* PakfireCache;
 typedef struct _PakfireFile* PakfireFile;
index f6831e80083a8563a9bfe7dd9972a2af2d5e9e78..42172ad67b1668814651b93efd9173eabd4d2c26 100644 (file)
 
 LIBPAKFIRE_0 {
 global:
+       # pakfire
+       pakfire_create;
+       pakfire_get_arch;
+       pakfire_get_path;
+       pakfire_ref;
+       pakfire_unref;
+
        # archive
        pakfire_archive_create;
        pakfire_archive_extract;
diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c
new file mode 100644 (file)
index 0000000..f1a08ac
--- /dev/null
@@ -0,0 +1,55 @@
+/*#############################################################################
+#                                                                             #
+# 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;
+}
index e2e9c09ee63bd0a3b57bdddd7f9342b305b14818..33024fa2a00c1dfc51c95f319600f68f04e36a60 100644 (file)
@@ -41,16 +41,12 @@ from .system import system
 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
@@ -68,7 +64,7 @@ class Pakfire(object):
                # 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)
 
index 694714458156724c775d63a2e73e95597e8ec182..a1eb6a8dc530f69eed7c6255c377acf452a774c3 100644 (file)
@@ -31,6 +31,7 @@ import time
 import uuid
 
 from . import _pakfire
+from . import arch
 from . import base
 from . import cgroup
 from . import config
@@ -451,6 +452,9 @@ class BuilderContext(object):
                # 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
 
@@ -484,11 +488,11 @@ class BuilderContext(object):
 
                # 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
index 870e31f5dba449eb205be7816bb23f63fa5d0d68..3d2098ad8734fdd505a7150a79d24988bfe95741 100644 (file)
@@ -124,7 +124,7 @@ class Repositories(object):
                # Handle variable expansion.
                replaces = {
                        "name" : name,
-                       "arch" : self.pakfire.arch.name,
+                       "arch" : self.pakfire.arch,
                }
 
                for k, v in list(_args.items()):
index f7c1b3974c0cb7222be9dbeb59186b8fc22f3878..4ad4b221a867f6f25877bb9032ab307e12321f2e 100644 (file)
@@ -184,7 +184,7 @@ class RepositoryRemote(base.RepositoryFactory):
                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)