From: Michael Tremer Date: Fri, 23 Apr 2021 14:51:16 +0000 (+0000) Subject: Drop selectors X-Git-Tag: 0.9.28~1285^2~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12145b0de4929822c39d82497f51350531e61340;p=pakfire.git Drop selectors These have been replaced by a simple string-parsing function Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index df2b7dc85..da4f815f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -180,8 +180,6 @@ _pakfire_la_SOURCES = \ src/_pakfire/repo.h \ src/_pakfire/request.c \ src/_pakfire/request.h \ - src/_pakfire/selector.c \ - src/_pakfire/selector.h \ src/_pakfire/solution.c \ src/_pakfire/solution.h \ src/_pakfire/step.c \ @@ -276,7 +274,6 @@ libpakfire_la_SOURCES = \ src/libpakfire/repolist.c \ src/libpakfire/request.c \ src/libpakfire/scriptlet.c \ - src/libpakfire/selector.c \ src/libpakfire/snapshot.c \ src/libpakfire/solution.c \ src/libpakfire/step.c \ @@ -315,7 +312,6 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/repolist.h \ src/libpakfire/include/pakfire/request.h \ src/libpakfire/include/pakfire/scriptlet.h \ - src/libpakfire/include/pakfire/selector.h \ src/libpakfire/include/pakfire/snapshot.h \ src/libpakfire/include/pakfire/solution.h \ src/libpakfire/include/pakfire/step.h \ diff --git a/src/_pakfire/_pakfiremodule.c b/src/_pakfire/_pakfiremodule.c index 818f5525b..937c843c7 100644 --- a/src/_pakfire/_pakfiremodule.c +++ b/src/_pakfire/_pakfiremodule.c @@ -41,7 +41,6 @@ #include "relation.h" #include "repo.h" #include "request.h" -#include "selector.h" #include "solution.h" #include "step.h" #include "transaction.h" @@ -179,13 +178,6 @@ PyMODINIT_FUNC PyInit__pakfire(void) { Py_INCREF(&RequestType); PyModule_AddObject(module, "Request", (PyObject *)&RequestType); - // Selector - if (PyType_Ready(&SelectorType) < 0) - return NULL; - - Py_INCREF(&SelectorType); - PyModule_AddObject(module, "Selector", (PyObject *)&SelectorType); - // Solution if (PyType_Ready(&SolutionType) < 0) return NULL; diff --git a/src/_pakfire/request.c b/src/_pakfire/request.c index 217dc28eb..06922bfdf 100644 --- a/src/_pakfire/request.c +++ b/src/_pakfire/request.c @@ -28,7 +28,6 @@ #include "problem.h" #include "relation.h" #include "request.h" -#include "selector.h" #include "transaction.h" static PyObject* Request_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { diff --git a/src/_pakfire/selector.c b/src/_pakfire/selector.c deleted file mode 100644 index 0b7140b53..000000000 --- a/src/_pakfire/selector.c +++ /dev/null @@ -1,127 +0,0 @@ -/*############################################################################# -# # -# 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 . # -# # -#############################################################################*/ - -#include - -#include -#include -#include -#include -#include - -#include "package.h" -#include "pakfire.h" -#include "selector.h" - -static PyObject* Selector_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { - SelectorObject* self = (SelectorObject *)type->tp_alloc(type, 0); - if (self) { - self->selector = NULL; - } - - return (PyObject *)self; -} - -static void Selector_dealloc(SelectorObject* self) { - pakfire_selector_unref(self->selector); - - Py_TYPE(self)->tp_free((PyObject *)self); -} - -static int Selector_init(SelectorObject* self, PyObject* args, PyObject* kwds) { - PakfireObject* pakfire; - - if (!PyArg_ParseTuple(args, "O!", &PakfireType, &pakfire)) - return -1; - - self->selector = pakfire_selector_create(pakfire->pakfire); - - return 0; -} - -static PyObject* Selector_set(SelectorObject* self, PyObject* args) { - int keyname; - int cmp_type; - const char* match; - - if (!PyArg_ParseTuple(args, "iis", &keyname, &cmp_type, &match)) - return NULL; - - int r = pakfire_selector_set(self->selector, keyname, cmp_type, match); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Selector_get_providers(SelectorObject* self) { - PakfirePackageList packagelist = pakfire_selector_providers(self->selector); - - PyObject* list = PyList_New(0); - for (unsigned int i = 0; i < pakfire_packagelist_count(packagelist); i++) { - PakfirePackage package = pakfire_packagelist_get(packagelist, i); - - PyObject* obj = new_package(&PackageType, package); - PyList_Append(list, obj); - - pakfire_package_unref(package); - Py_DECREF(obj); - } - - pakfire_packagelist_unref(packagelist); - - return list; -} - -static struct PyGetSetDef Selector_getsetters[] = { - { - "providers", - (getter)Selector_get_providers, - NULL, - NULL, - NULL - }, - { NULL }, -}; - -static struct PyMethodDef Selector_methods[] = { - { - "set", - (PyCFunction)Selector_set, - METH_VARARGS, - NULL - }, - { NULL }, -}; - -PyTypeObject SelectorType = { - PyVarObject_HEAD_INIT(NULL, 0) - tp_name: "_pakfire.Selector", - tp_basicsize: sizeof(SelectorObject), - tp_flags: Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - tp_new: Selector_new, - tp_dealloc: (destructor)Selector_dealloc, - tp_init: (initproc)Selector_init, - tp_doc: "Selector object", - tp_methods: Selector_methods, - tp_getset: Selector_getsetters, -}; diff --git a/src/_pakfire/selector.h b/src/_pakfire/selector.h deleted file mode 100644 index dbeb8ffef..000000000 --- a/src/_pakfire/selector.h +++ /dev/null @@ -1,35 +0,0 @@ -/*############################################################################# -# # -# 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 . # -# # -#############################################################################*/ - -#ifndef PYTHON_PAKFIRE_SELECTOR_H -#define PYTHON_PAKFIRE_SELECTOR_H - -#include - -#include - -typedef struct { - PyObject_HEAD - PakfireSelector selector; -} SelectorObject; - -extern PyTypeObject SelectorType; - -#endif /* PYTHON_PAKFIRE_SELECTOR_H */ diff --git a/src/libpakfire/include/pakfire/selector.h b/src/libpakfire/include/pakfire/selector.h deleted file mode 100644 index a3b5eaa55..000000000 --- a/src/libpakfire/include/pakfire/selector.h +++ /dev/null @@ -1,41 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2013 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 . # -# # -#############################################################################*/ - -#ifndef PAKFIRE_SELECTOR_H -#define PAKFIRE_SELECTOR_H - -#include -#include - -#include -#include - -PakfireSelector pakfire_selector_create(Pakfire pakfire); - -PakfireSelector pakfire_selector_ref(PakfireSelector selector); -PakfireSelector pakfire_selector_unref(PakfireSelector selector); - -int pakfire_selector_set(PakfireSelector selector, int keyname, int cmp_type, const char* match); - -PakfirePackageList pakfire_selector_providers(PakfireSelector selector); - -int pakfire_selector2queue(const PakfireSelector selector, Queue* queue, int solver_action); - -#endif /* PAKFIRE_SELECTOR_H */ diff --git a/src/libpakfire/include/pakfire/types.h b/src/libpakfire/include/pakfire/types.h index d4ef2f29f..f6475ad57 100644 --- a/src/libpakfire/include/pakfire/types.h +++ b/src/libpakfire/include/pakfire/types.h @@ -37,7 +37,6 @@ typedef struct _PakfireProblem* PakfireProblem; typedef struct _PakfireRelation* PakfireRelation; typedef struct _PakfireRelationList* PakfireRelationList; typedef struct _PakfireRepo* PakfireRepo; -typedef struct _PakfireSelector* PakfireSelector; typedef struct _PakfireSolution* PakfireSolution; typedef struct _PakfireStep* PakfireStep; typedef struct _PakfireTransaction* PakfireTransaction; diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 579353349..aa8f9fdde 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -390,13 +390,6 @@ global: pakfire_request_unref; pakfire_request_verify; - # selector - pakfire_selector_create; - pakfire_selector_providers; - pakfire_selector_ref; - pakfire_selector_set; - pakfire_selector_unref; - # snapshot pakfire_snapshot_create; pakfire_snapshot_restore; diff --git a/src/libpakfire/selector.c b/src/libpakfire/selector.c deleted file mode 100644 index dded62959..000000000 --- a/src/libpakfire/selector.c +++ /dev/null @@ -1,379 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2013 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 . # -# # -#############################################################################*/ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct _PakfireSelector { - Pakfire pakfire; - PakfireFilter f_name; - PakfireFilter f_provides; - PakfireFilter f_evr; - PakfireFilter f_arch; - PakfireFilter f_group; - int nrefs; -}; - -PAKFIRE_EXPORT PakfireSelector pakfire_selector_create(Pakfire pakfire) { - PakfireSelector selector = calloc(1, sizeof(*selector)); - if (selector) { - DEBUG(pakfire, "Allocated Selector at %p\n", selector); - selector->nrefs = 1; - - selector->pakfire = pakfire_ref(pakfire); - - selector->f_arch = NULL; - selector->f_name = NULL; - selector->f_evr = NULL; - selector->f_provides = NULL; - selector->f_group = NULL; - } - - return selector; -} - -PAKFIRE_EXPORT PakfireSelector pakfire_selector_ref(PakfireSelector selector) { - selector->nrefs++; - - return selector; -} - -static void pakfire_selector_free(PakfireSelector selector) { - DEBUG(selector->pakfire, "Releasing Selector at %p\n", selector); - - pakfire_unref(selector->pakfire); - free(selector); -} - -PAKFIRE_EXPORT PakfireSelector pakfire_selector_unref(PakfireSelector selector) { - if (!selector) - return NULL; - - if (--selector->nrefs > 0) - return selector; - - pakfire_selector_free(selector); - return NULL; -} - -static int pakfire_selector_valid_setting(int keyname, int cmp_type) { - switch (keyname) { - case PAKFIRE_PKG_ARCH: - case PAKFIRE_PKG_EVR: - case PAKFIRE_PKG_GROUP: - case PAKFIRE_PKG_VERSION: - case PAKFIRE_PKG_PROVIDES: - return cmp_type == PAKFIRE_EQ; - - case PAKFIRE_PKG_NAME: - return (cmp_type == PAKFIRE_EQ || cmp_type == PAKFIRE_GLOB); - - default: - return 0; - } -} - -static void pakfire_selector_replace_filter(PakfireFilter* filter, int keyname, int cmp_type, const char* match) { - if (*filter) - pakfire_filter_free(*filter); - - PakfireFilter f = pakfire_filter_create(); - - f->keyname = keyname; - f->cmp_type = cmp_type; - f->match = strdup(match); - - *filter = f; -} - -PAKFIRE_EXPORT int pakfire_selector_set(PakfireSelector selector, int keyname, int cmp_type, const char* match) { - if (!pakfire_selector_valid_setting(keyname, cmp_type)) - return 1; - - PakfireFilter* filter = NULL; - - switch (keyname) { - case PAKFIRE_PKG_ARCH: - filter = &selector->f_arch; - break; - - case PAKFIRE_PKG_EVR: - case PAKFIRE_PKG_VERSION: - filter = &selector->f_evr; - break; - - case PAKFIRE_PKG_NAME: - if (selector->f_provides) - return 1; - - filter = &selector->f_name; - break; - - case PAKFIRE_PKG_PROVIDES: - if (selector->f_name) - return 1; - - filter = &selector->f_provides; - break; - - case PAKFIRE_PKG_GROUP: - if (selector->f_group) - return 1; - - filter = &selector->f_group; - break; - - default: - return 1; - } - - pakfire_selector_replace_filter(filter, keyname, cmp_type, match); - - return 0; -} - -PAKFIRE_EXPORT PakfirePackageList pakfire_selector_providers(PakfireSelector selector) { - Queue q; - queue_init(&q); - - pakfire_selector2queue(selector, &q, 0); - - PakfirePackageList list = pakfire_packagelist_from_queue(selector->pakfire, &q); - - queue_free(&q); - - return list; -} - -static int queue_has(Queue* queue, Id what, Id id) { - for (int i = 0; i < queue->count; i += 2) { - if (queue->elements[i] == what && queue->elements[i + 1] == id) - return 1; - } - - return 0; -} - -static Id str2archid(Pool* pool, const char* arch) { - // originally from libsolv/examples/solv.c:str2archid() - - if (!*arch) - return 0; - - Id id = pool_str2id(pool, arch, 0); - if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH) - return id; - - if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id])) - return 0; - - return id; -} - -static int filter_arch2queue(Pakfire pakfire, const PakfireFilter f, Queue* queue) { - if (f == NULL) - return 0; - - if (f->cmp_type != PAKFIRE_EQ) - return 1; - - Pool* pool = pakfire_get_solv_pool(pakfire); - Id archid = str2archid(pool, f->match); - if (archid == 0) - return 1; - - for (int i = 0; i < queue->count; i += 2) { - Id dep = queue->elements[i + 1]; - - queue->elements[i + 1] = pool_rel2id(pool, dep, archid, REL_ARCH, 1); - queue->elements[i] |= SOLVER_SETARCH; - } - - return 0; -} - -static int filter_evr2queue(Pakfire pakfire, const PakfireFilter f, Queue* queue) { - if (f == NULL) - return 0; - - if (f->cmp_type != PAKFIRE_EQ) - return 1; - - Pool* pool = pakfire_get_solv_pool(pakfire); - Id evr = pool_str2id(pool, f->match, 1); - - for (int i = 0; i < queue->count; i += 2) { - Id dep = queue->elements[i + 1]; - queue->elements[i + 1] = pool_rel2id(pool, dep, evr, REL_EQ, 1); - queue->elements[i] |= PAKFIRE_PKG_VERSION ? SOLVER_SETEV : SOLVER_SETEVR; - } - - return 0; -} - -static int filter_name2queue(Pakfire pakfire, const PakfireFilter f, Queue* queue) { - if (f == NULL) - return 0; - - Pool* pool = pakfire_get_solv_pool(pakfire); - const char* name = f->match; - Id id; - Dataiterator di; - - switch (f->cmp_type) { - case PAKFIRE_EQ: - id = pool_str2id(pool, name, 0); - if (id) - queue_push2(queue, SOLVER_SOLVABLE_NAME, id); - break; - - case PAKFIRE_GLOB: - dataiterator_init(&di, pool, 0, 0, SOLVABLE_NAME, name, SEARCH_GLOB); - - while (dataiterator_step(&di)) { - Id id = *di.idp; - - if (queue_has(queue, SOLVABLE_NAME, id)) - continue; - - queue_push2(queue, SOLVER_SOLVABLE_NAME, id); - } - - dataiterator_free(&di); - break; - - default: - return 1; - } - - return 0; -} - -static int filter_provides2queue(Pakfire pakfire, const PakfireFilter f, Queue* queue) { - if (f == NULL) - return 0; - - Pool* pool = pakfire_get_solv_pool(pakfire); - Id id; - - switch (f->cmp_type) { - case PAKFIRE_EQ: - id = pool_str2id(pool, f->match, 0); - if (id) - queue_push2(queue, SOLVER_SOLVABLE_PROVIDES, id); - break; - - default: - return 1; - } - - return 0; -} - -static int filter_group2queue(Pakfire pakfire, const PakfireFilter f, Queue* queue) { - if (f == NULL) - return 0; - - Pool* pool = pakfire_get_solv_pool(pakfire); - const char* name = f->match; - Dataiterator di; - - switch (f->cmp_type) { - case PAKFIRE_EQ: - dataiterator_init(&di, pool, 0, 0, SOLVABLE_GROUP, name, SEARCH_SUBSTRING); - - while (dataiterator_step(&di)) { - Solvable* s = pool->solvables + di.solvid; - - if (queue_has(queue, SOLVABLE_NAME, s->name)) - continue; - - queue_push2(queue, SOLVER_SOLVABLE_NAME, s->name); - } - - dataiterator_free(&di); - break; - - default: - return 1; - } - - return 0; -} - -PAKFIRE_EXPORT int pakfire_selector2queue(const PakfireSelector selector, Queue* queue, int solver_action) { - int ret = 0; - - Queue queue_selector; - queue_init(&queue_selector); - - if (selector->f_name == NULL && selector->f_provides == NULL && selector->f_group == NULL) { - // no name or provides in the selector is an erro - ret = 1; - goto finish; - } - - pakfire_pool_apply_changes(selector->pakfire); - - ret = filter_name2queue(selector->pakfire, selector->f_name, &queue_selector); - if (ret) - goto finish; - - ret = filter_provides2queue(selector->pakfire, selector->f_provides, &queue_selector); - if (ret) - goto finish; - - ret = filter_arch2queue(selector->pakfire, selector->f_arch, &queue_selector); - if (ret) - goto finish; - - ret = filter_evr2queue(selector->pakfire, selector->f_evr, &queue_selector); - if (ret) - goto finish; - - ret = filter_group2queue(selector->pakfire, selector->f_group, &queue_selector); - if (ret) - goto finish; - - for (int i = 0; i < queue_selector.count; i += 2) { - queue_push2(queue, - queue_selector.elements[i] | solver_action, - queue_selector.elements[i + 1] - ); - } - -finish: - queue_free(&queue_selector); - - return ret; -} diff --git a/src/pakfire/base.py b/src/pakfire/base.py index b21ebfe60..46f36c27d 100644 --- a/src/pakfire/base.py +++ b/src/pakfire/base.py @@ -173,21 +173,6 @@ class PakfireContext(object): return request.solve(**kwargs) - for req in requires: - # Handle groups - # TODO should move into libpakfire - if req.startswith("@"): - sel = _pakfire.Selector(self.pakfire) - sel.set(_pakfire.PAKFIRE_PKG_GROUP, _pakfire.PAKFIRE_EQ, req[1:]) - request.install(sel) - continue - - # Handle everything else - relation = _pakfire.Relation(self.pakfire, req) - request.install(relation) - - return request.solve(**kwargs) - def reinstall(self, pkgs, strict=False, logger=None): """ Reinstall one or more packages