]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
libpakfire: Export repositories to Python
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 19 Apr 2021 14:05:39 +0000 (14:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 19 Apr 2021 14:05:39 +0000 (14:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/libpakfire.sym
src/libpakfire/pakfire.c
src/pakfire/base.py
src/pakfire/repository/__init__.py [deleted file]

index 848861e85853789689dafa601350599e831ffd93..59f99b647213184ce4e68d3d76855bb0d8aaf12f 100644 (file)
@@ -143,13 +143,6 @@ pakfire_packagesdir = $(pythondir)/pakfire/packages
 
 # ------------------------------------------------------------------------------
 
-pakfire_repository_PYTHON = \
-       src/pakfire/repository/__init__.py
-
-pakfire_repositorydir = $(pythondir)/pakfire/repository
-
-# ------------------------------------------------------------------------------
-
 pakfire_ui_PYTHON = \
        src/pakfire/ui/__init__.py \
        src/pakfire/ui/base.py \
@@ -279,6 +272,7 @@ libpakfire_la_SOURCES = \
        src/libpakfire/relation.c \
        src/libpakfire/relationlist.c \
        src/libpakfire/repo.c \
+       src/libpakfire/repolist.c \
        src/libpakfire/request.c \
        src/libpakfire/scriptlet.c \
        src/libpakfire/selector.c \
@@ -317,6 +311,7 @@ pkginclude_HEADERS += \
        src/libpakfire/include/pakfire/relation.h \
        src/libpakfire/include/pakfire/relationlist.h \
        src/libpakfire/include/pakfire/repo.h \
+       src/libpakfire/include/pakfire/repolist.h \
        src/libpakfire/include/pakfire/request.h \
        src/libpakfire/include/pakfire/scriptlet.h \
        src/libpakfire/include/pakfire/selector.h \
index 98e774a6013d000b155e438651f65e7a796fc9df..ad12e8a394fc3fa6272ef2f5d4878b3848d8ef60 100644 (file)
@@ -29,6 +29,7 @@
 #include <pakfire/pakfire.h>
 #include <pakfire/key.h>
 #include <pakfire/repo.h>
+#include <pakfire/repolist.h>
 #include <pakfire/snapshot.h>
 #include <pakfire/util.h>
 
@@ -791,6 +792,36 @@ static PyObject* Pakfire_restore_snapshot(PakfireObject* self, PyObject* args) {
        Py_RETURN_NONE;
 }
 
+static PyObject* Pakfire_get_repos(PakfireObject* self) {
+       struct pakfire_repolist* repos = pakfire_get_repos(self->pakfire);
+       if (!repos) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               return NULL;
+       }
+
+       const size_t l = pakfire_repolist_size(repos);
+
+       PyObject* list = PyList_New(l);
+       if (!list)
+               goto ERROR;
+
+       for (unsigned int i = 0; i < l; i++) {
+               PakfireRepo repo = pakfire_repolist_get(repos, i);
+               if (!repo)
+                       continue;
+
+               PyObject* obj = new_repo(&RepoType, repo);
+               PyList_SET_ITEM(list, i, obj);
+
+               pakfire_repo_unref(repo);
+       }
+
+ERROR:
+       pakfire_repolist_unref(repos);
+
+       return list;
+}
+
 static struct PyMethodDef Pakfire_methods[] = {
        {
                "bind",
@@ -946,6 +977,13 @@ static struct PyGetSetDef Pakfire_getsetters[] = {
                NULL,
                NULL
        },
+       {
+               "repos",
+               (getter)Pakfire_get_repos,
+               NULL,
+               NULL,
+               NULL
+       },
     { NULL },
 };
 
index 32ffbfa46eb1c25db108196a73a46d548071d2c7..a81faf31e7f4c953d8ee054d34f1ae2828e218c5 100644 (file)
@@ -27,6 +27,7 @@
 #include <time.h>
 
 #include <pakfire/parser.h>
+#include <pakfire/repolist.h>
 #include <pakfire/types.h>
 
 int pakfire_create(Pakfire* pakfire, const char* path, const char* arch, const char* conf);
@@ -54,6 +55,7 @@ int pakfire_version_compare(Pakfire pakfire, const char* evr1, const char* evr2)
 
 size_t pakfire_count_packages(Pakfire pakfire);
 
+struct pakfire_repolist* pakfire_get_repos(Pakfire pakfire);
 PakfireRepo pakfire_get_repo(Pakfire pakfire, const char* name);
 PakfireRepo pakfire_get_installed_repo(Pakfire pakfire);
 
index 5181eac6c7cbd319a5607e3be2450abb619e78eb..9607d8c5b611d16417ac3b12d720edc072befe42 100644 (file)
@@ -36,6 +36,7 @@ global:
        pakfire_get_path;
        pakfire_get_pool;
        pakfire_get_repo;
+       pakfire_get_repos;
        pakfire_make_cache_path;
        pakfire_make_path;
        pakfire_read_makefile;
@@ -321,6 +322,16 @@ global:
        pakfire_repo_write_solv_fp;
        pakfire_repo_unref;
 
+       # repolist
+       pakfire_repolist_append;
+       pakfire_repolist_clear;
+       pakfire_repolist_create;
+       pakfire_repolist_empty;
+       pakfire_repolist_get;
+       pakfire_repolist_size;
+       pakfire_repolist_ref;
+       pakfire_repolist_unref;
+
        # relation
        pakfire_relation_create;
        pakfire_relation_create_from_id;
index 8ae3e1e828153b6ed3e2b4cb252194c2604ff75c..1c308f51871350b19fa31afde17c120b821cb9e6 100644 (file)
@@ -970,6 +970,40 @@ void pakfire_pool_apply_changes(Pakfire pakfire) {
        }
 }
 
+PAKFIRE_EXPORT struct pakfire_repolist* pakfire_get_repos(Pakfire pakfire) {
+       struct pakfire_repolist* list;
+
+       int r = pakfire_repolist_create(&list);
+       if (r)
+               return NULL;
+
+       Pool* pool = pakfire_get_solv_pool(pakfire);
+       Repo* solv_repo;
+       int i;
+
+       FOR_REPOS(i, solv_repo) {
+               PakfireRepo repo = pakfire_repo_create_from_repo(pakfire, solv_repo);
+               if (!repo) {
+                       r = 1;
+                       goto ERROR;
+               }
+
+               r = pakfire_repolist_append(list, repo);
+               if (r) {
+                       pakfire_repo_unref(repo);
+                       goto ERROR;
+               }
+
+               pakfire_repo_unref(repo);
+       }
+
+       return list;
+
+ERROR:
+       pakfire_repolist_unref(list);
+       return NULL;
+}
+
 PAKFIRE_EXPORT PakfireRepo pakfire_get_repo(Pakfire pakfire, const char* name) {
        Pool* pool = pakfire_get_solv_pool(pakfire);
 
index 93cdb06be4513b5c135fa8692cf19766e25b7095..17c5d3b11bf5078803ddacf0126e07608df09921 100644 (file)
@@ -28,7 +28,6 @@ from . import _pakfire
 from . import distro
 from . import logger
 from . import packages
-from . import repository
 from . import util
 
 from .config import Config
@@ -52,8 +51,6 @@ class Pakfire(_pakfire.Pakfire):
                # Load configuration
                self.config = config or Config("general.conf")
 
-               self.repos = repository.Repositories(self)
-
        def _setup_logger(self):
                log = logging.getLogger("pakfire")
                log.propagate = 0
diff --git a/src/pakfire/repository/__init__.py b/src/pakfire/repository/__init__.py
deleted file mode 100644 (file)
index bd9982c..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/python
-###############################################################################
-#                                                                             #
-# Pakfire - The IPFire package management system                              #
-# Copyright (C) 2011 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/>.       #
-#                                                                             #
-###############################################################################
-
-import logging
-log = logging.getLogger("pakfire")
-
-class Repositories(object):
-       """
-               Class that loads all repositories from the configuration files.
-
-               This is the place where repositories can be activated or deactivated.
-       """
-
-       def __init__(self, pakfire):
-               self.pakfire = pakfire
-
-               # Place to store the repositories
-               self.__repos = {}
-
-       def __iter__(self):
-               repositories = list(self.__repos.values())
-               repositories.sort()
-
-               return iter(repositories)
-
-       def __len__(self):
-               """
-                       Return the count of enabled repositories.
-               """
-               return len([r for r in self if r.enabled])
-
-       @property
-       def distro(self):
-               return self.pakfire.distro
-
-       def get_repo(self, name):
-               """
-                       Get the repository with the given name, if not available, return
-                       the dummy repository.
-               """
-               try:
-                       return self.__repos[name]
-               except KeyError:
-                       pass
-
-       def clean(self):
-               log.info("Cleaning up all repository caches...")
-
-               for repo in self:
-                       repo.clean()