From: Michael Tremer Date: Fri, 19 Mar 2021 18:45:25 +0000 (+0000) Subject: Move offline setting to Pakfire instances X-Git-Tag: 0.9.28~1285^2~505 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72caad767aa796b4ab51092f93af774faa79974c;p=pakfire.git Move offline setting to Pakfire instances Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 6dd465920..dba2fecee 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -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, diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 9809e0b30..4468ae9c4 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -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); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 46b252e44..ff5208f1f 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -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; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index a7e77abf6..1abe0982f 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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); } diff --git a/src/pakfire/base.py b/src/pakfire/base.py index e2a34b2b5..204a0f5de 100644 --- a/src/pakfire/base.py +++ b/src/pakfire/base.py @@ -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)