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;
{
"search",
(PyCFunction)Pakfire_search,
- METH_VARARGS,
+ METH_VARARGS|METH_KEYWORDS,
NULL
},
{
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);
struct pakfire_packagelist** list) {
Queue matches;
Dataiterator di;
+ int dflags = 0;
// Refresh repositories
int r = pakfire_refresh(pakfire, 0);
// 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,
};
// 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
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
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)