]> git.ipfire.org Git - pakfire.git/commitdiff
Move offline setting to Pakfire instances
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Mar 2021 18:45:25 +0000 (18:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Mar 2021 18:50:17 +0000 (18:50 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/libpakfire.sym
src/libpakfire/pakfire.c
src/pakfire/base.py

index 6dd4659205c49acb5ef91f8d7db4fc6f7a935274..dba2feceef058c066f2c1790de05ec35f3ee43f4 100644 (file)
@@ -48,10 +48,12 @@ static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
 }
 
 static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
+       char* kwlist[] = { "path", "arch", "offline", NULL };
        const char* path = NULL;
-    const char* arch = NULL;
+       const char* arch = NULL;
+       int offline = 0;
 
-       if (!PyArg_ParseTuple(args, "s|z", &path, &arch))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|zp", kwlist, &path, &arch, &offline))
                return -1;
 
        // Create a new Pakfire instance
@@ -77,6 +79,10 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
                return -1;
     }
 
+       // Set offline mode if requested
+       if (offline)
+               pakfire_set_offline(self->pakfire, 1);
+
        return 0;
 }
 
@@ -679,6 +685,21 @@ static PyObject* Pakfire_dist(PakfireObject* self, PyObject* args) {
        Py_RETURN_NONE;
 }
 
+static PyObject* Pakfire_get_offline(PakfireObject* self) {
+       int offline = pakfire_get_offline(self->pakfire);
+
+       if (offline)
+               Py_RETURN_TRUE;
+
+       Py_RETURN_FALSE;
+}
+
+static int Pakfire_set_offline(PakfireObject* self, PyObject* value) {
+       pakfire_set_offline(self->pakfire, PyObject_IsTrue(value));
+
+       return 0;
+}
+
 static struct PyMethodDef Pakfire_methods[] = {
        {
                "dist",
@@ -790,6 +811,13 @@ static struct PyGetSetDef Pakfire_getsetters[] = {
                NULL,
                NULL
        },
+       {
+               "offline",
+               (getter)Pakfire_get_offline,
+               (setter)Pakfire_set_offline,
+               NULL,
+               NULL,
+       },
     {
                "path",
                (getter)Pakfire_get_path,
index 9809e0b30ceeee78366d3bcf9aa7308572971259..4468ae9c43a79d3a8a7aeb533399bc0ca976e9bf 100644 (file)
@@ -42,6 +42,9 @@ int pakfire_deactivate(Pakfire pakfire);
 
 const char* pakfire_get_arch(Pakfire pakfire);
 
+int pakfire_get_offline(Pakfire pakfire);
+void pakfire_set_offline(Pakfire pakfire, int offline);
+
 const char** pakfire_get_installonly(Pakfire pakfire);
 void pakfire_set_installonly(Pakfire pakfire, const char** installonly);
 
index 46b252e44f1d8c82114e95d8bd60a1075aa0396a..ff5208f1f8420bdf89e09ae6a80757169767a1e9 100644 (file)
@@ -31,6 +31,7 @@ global:
        pakfire_get_arch;
        pakfire_get_installed_repo;
        pakfire_get_installonly;
+       pakfire_get_offline;
        pakfire_get_path;
        pakfire_get_pool;
        pakfire_get_repo;
@@ -40,6 +41,7 @@ global:
        pakfire_ref;
        pakfire_search;
        pakfire_set_installonly;
+       pakfire_set_offline;
        pakfire_unref;
        pakfire_version_compare;
        pakfire_whatprovides;
index a7e77abf66e08d3213cb4b531a8c0241fbbcfff3..1abe0982fa80b826af638123b04b9f276d96a90f 100644 (file)
@@ -55,6 +55,8 @@ struct _Pakfire {
        char cache_path[PATH_MAX];
        char arch[ARCH_MAX];
 
+       int offline;
+
        // Pool stuff
        Pool* pool;
        int pool_ready;
@@ -466,6 +468,14 @@ PAKFIRE_EXPORT const char* pakfire_get_arch(Pakfire pakfire) {
        return pakfire->arch;
 }
 
+PAKFIRE_EXPORT int pakfire_get_offline(Pakfire pakfire) {
+       return pakfire->offline;
+}
+
+PAKFIRE_EXPORT void pakfire_set_offline(Pakfire pakfire, int offline) {
+       pakfire->offline = offline;
+}
+
 PAKFIRE_EXPORT int pakfire_version_compare(Pakfire pakfire, const char* evr1, const char* evr2) {
        return pool_evrcmp_str(pakfire->pool, evr1, evr2, EVRCMP_COMPARE);
 }
index e2a34b2b57c357a41992146f25e7322a4f64a5db..204a0f5de4e8654a74e5173eec8a3a92584d9812 100644 (file)
@@ -41,7 +41,7 @@ class Pakfire(_pakfire.Pakfire):
        __version__ = PAKFIRE_VERSION
 
        def __init__(self, path="/", config=None, arch=None, distro=None, offline=False):
-               _pakfire.Pakfire.__init__(self, path, arch)
+               _pakfire.Pakfire.__init__(self, path, arch, offline=offline)
 
                # Initialise logging system
                self.log = self._setup_logger()
@@ -49,9 +49,6 @@ class Pakfire(_pakfire.Pakfire):
                # Default to system distribution
                self.distro = distro or system.distro
 
-               # Offline
-               self.offline = offline
-
                # Check if we are operating as the root user
                self.check_root_user()
 
@@ -108,17 +105,6 @@ class Pakfire(_pakfire.Pakfire):
        def __exit__(self, type, value, traceback):
                pass
 
-       def get_offline(self):
-               """
-                       A shortcut that indicates if the system is running in offline mode.
-               """
-               return self._offline or self.config.get("downloader", "offline", False)
-
-       def set_offline(self, offline):
-               self._offline = offline
-
-       offline = property(get_offline, set_offline)
-
        def refresh_repositories(self, force=False):
                for repo in self.repos:
                        repo.refresh(force=force)