From f1ab3110ae1826ffe28f997abce2958a5eada46b Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 17 Jul 2011 12:08:02 +0200 Subject: [PATCH] Implement searching the pool. --- pakfire/base.py | 4 +++- po/pakfire.pot | 2 +- src/_pakfiremodule.c | 1 + src/pool.c | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/pakfire/base.py b/pakfire/base.py index 2d2562131..c1673365c 100644 --- a/pakfire/base.py +++ b/pakfire/base.py @@ -207,7 +207,9 @@ class Pakfire(object): def search(self, pattern): # Do the search. - pkgs = self.repos.search(pattern) + pkgs = [] + for solv in self.pool.search(pattern): + pkgs.append(packages.SolvPackage(self, solv)) # Return the output as a package listing. return packages.PackageListing(pkgs) diff --git a/po/pakfire.pot b/po/pakfire.pot index 8837d1fa0..f1d2d7bb3 100644 --- a/po/pakfire.pot +++ b/po/pakfire.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-07-16 22:20+0200\n" +"POT-Creation-Date: 2011-07-17 12:07+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/src/_pakfiremodule.c b/src/_pakfiremodule.c index 7f4255ecc..54a671f3b 100644 --- a/src/_pakfiremodule.c +++ b/src/_pakfiremodule.c @@ -20,6 +20,7 @@ static PyMethodDef Pool_methods[] = { {"size", (PyCFunction)Pool_size, METH_NOARGS, NULL}, {"set_installed", (PyCFunction)Pool_set_installed, METH_VARARGS, NULL}, {"providers", (PyCFunction)Pool_providers, METH_VARARGS, NULL}, + {"search", (PyCFunction)Pool_search, METH_VARARGS, NULL}, { NULL, NULL, 0, NULL } }; diff --git a/src/pool.c b/src/pool.c index d80323439..c70e4093a 100644 --- a/src/pool.c +++ b/src/pool.c @@ -88,8 +88,39 @@ PyObject *Pool_size(PoolObject *self) { return Py_BuildValue("i", pool->nsolvables); } +PyObject *_Pool_search(Pool *pool, Repo *repo, const char *match, int option) { + // Prepare the pool, so we can search in it. + _Pool_prepare(pool); + + Dataiterator d; + dataiterator_init(&d, pool, repo, 0, 0, match, option); + + PyObject *list = PyList_New(0); + + SolvableObject *solvable; + while (dataiterator_step(&d)) { + solvable = PyObject_New(SolvableObject, &SolvableType); + solvable->_pool = pool; + solvable->_id = d.solvid; + + PyList_Append(list, (PyObject *)solvable); + } + + dataiterator_free(&d); + + Py_INCREF(list); + return list; +} + PyObject *Pool_search(PoolObject *self, PyObject *args) { - Py_RETURN_NONE; /* XXX to be done */ + const char *match = NULL; + int option = SEARCH_SUBSTRING; + + if (!PyArg_ParseTuple(args, "s|i", &match, &option)) { + /* XXX raise exception */ + } + + return _Pool_search(self->_pool, NULL, match, option); } PyObject *Pool_set_installed(PoolObject *self, PyObject *args) { -- 2.39.5