]> git.ipfire.org Git - pakfire.git/commitdiff
CLI: Make "info" work again by limiting search to package names only
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Jun 2021 17:47:44 +0000 (17:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Jun 2021 17:47:44 +0000 (17:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c
src/pakfire/cli.py

index f87df053da6714b58b0b63e5a2fbe53c815f2ccb..2d1ea43c79f3f2def7baa9b424614a2cb6fa2eb6 100644 (file)
@@ -483,14 +483,21 @@ static PyObject* Pakfire_whatrequires(PakfireObject* self, PyObject* args) {
        return obj;
 }
 
-static PyObject* Pakfire_search(PakfireObject* self, PyObject* args) {
+static PyObject* Pakfire_search(PakfireObject* self, PyObject* args, PyObject* kwds) {
+       char* kwlist[] = { "pattern", "name_only", NULL };
        struct pakfire_packagelist* list = NULL;
-       const char* what = NULL;
+       const char* pattern = NULL;
+       int name_only = 0;
+       int flags = 0;
 
-       if (!PyArg_ParseTuple(args, "s", &what))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|$p", kwlist, &pattern, &name_only))
                return NULL;
 
-       int r = pakfire_search(self->pakfire, what, 0, &list);
+       // Search for package names only
+       if (name_only)
+               flags |= PAKFIRE_SEARCH_NAME_ONLY;
+
+       int r = pakfire_search(self->pakfire, pattern, flags, &list);
        if (r) {
                PyErr_SetFromErrno(PyExc_OSError);
                return NULL;
@@ -1001,7 +1008,7 @@ static struct PyMethodDef Pakfire_methods[] = {
        {
                "search",
                (PyCFunction)Pakfire_search,
-               METH_VARARGS,
+               METH_VARARGS|METH_KEYWORDS,
                NULL
        },
        {
index d6d4f37440819fef0a61623032c0fe324d65a18e..78d7983660791e4e5acae54471b6c3c754f1b02e 100644 (file)
@@ -70,6 +70,13 @@ int pakfire_whatprovides(Pakfire pakfire, const char* what, int flags,
        struct pakfire_packagelist** list);
 int pakfire_whatrequires(Pakfire pakfire, const char* what, int flags,
        struct pakfire_packagelist** list);
+
+// Search
+
+enum pakfire_search_flags {
+       PAKFIRE_SEARCH_NAME_ONLY        = (1 << 0),
+};
+
 int pakfire_search(Pakfire pakfire, const char* what, int flags,
        struct pakfire_packagelist** list);
 
index 8124d429097afd7bbece17aa40d68a250a5668be..c7e89b5b4cfac449abf60bc9fb74e6d8ec5b90ce 100644 (file)
@@ -1339,6 +1339,7 @@ PAKFIRE_EXPORT int pakfire_search(Pakfire pakfire, const char* what, int flags,
                struct pakfire_packagelist** list) {
        Queue matches;
        Dataiterator di;
+       int dflags = 0;
 
        // Refresh repositories
        int r = pakfire_refresh(pakfire, 0);
@@ -1351,10 +1352,15 @@ PAKFIRE_EXPORT int pakfire_search(Pakfire pakfire, const char* what, int flags,
        // Initialize the result queue
        queue_init(&matches);
 
+       if (flags & PAKFIRE_SEARCH_NAME_ONLY)
+               dflags = SEARCH_STRING|SEARCH_GLOB;
+       else
+               dflags = SEARCH_SUBSTRING|SEARCH_NOCASE|SEARCH_GLOB;
+
        // Setup the data interator
-       dataiterator_init(&di, pakfire->pool, 0, 0, 0, what, SEARCH_SUBSTRING|SEARCH_NOCASE);
+       dataiterator_init(&di, pakfire->pool, 0, 0, 0, what, dflags);
 
-       Id keys[] = {
+       const Id keys[] = {
                SOLVABLE_NAME,
                SOLVABLE_SUMMARY,
                SOLVABLE_DESCRIPTION,
@@ -1362,12 +1368,16 @@ PAKFIRE_EXPORT int pakfire_search(Pakfire pakfire, const char* what, int flags,
        };
 
        // Search through these keys and add matches to the queue
-       for (Id* key = keys; *key; key++) {
+       for (const Id* key = keys; *key; key++) {
                dataiterator_set_keyname(&di, *key);
                dataiterator_set_search(&di, 0, 0);
 
                while (dataiterator_step(&di))
                        queue_pushunique(&matches, di.solvid);
+
+               // Stop after name
+               if (flags & PAKFIRE_SEARCH_NAME_ONLY)
+                       break;
        }
 
        // Convert matches to package list
index 73694014e482c0630b5a70e6bbf855d33fbddb40..b52a3acd6d1b94ed1adb337a6e08b1aa7cd8cc63 100644 (file)
@@ -74,8 +74,7 @@ class Cli(object):
                        help=_("Print some information about the given package(s)"))
                info.add_argument("--long", action="store_true",
                        help=_("Show more information"))
-               info.add_argument("package", nargs="+",
-                       help=_("Give at least the name of one package"))
+               info.add_argument("package", help=_("Give at least the name of one package"))
                info.set_defaults(func=self.handle_info)
 
                # install
@@ -243,7 +242,7 @@ class Cli(object):
        def handle_info(self, ns):
                p = self.pakfire(ns)
 
-               for pkg in p.info(ns.package):
+               for pkg in p.search(ns.package, name_only=True):
                        s = pkg.dump(long=ns.long)
                        print(s)