[three]Bean

Querying Gnome-Shell Search Providers Over DBUS with Python

Oct 31, 2012 | categories: python, dbus, gnome, fedora View Comments

I'm working on a gnome-shell search provider to query the Fedora Packages webapp with the pkgwat python api.

In older versions of the gnome-shell, this used to be super simple -- you would just drop an XML file in /usr/share/gnome-shell/open-search-providers that defined a URL for where to search for stuff.

GNOME changed the way this all worked in gnome-shell 3.6 and you have to have an actual dbus service that returns results now. I haven't figured that part all out yet but I'm on the way.

Part of the first step was figuring out how the existing search providers worked, so I wrote this little python snippet to query the Documents search provider. Maybe you'll find it useful:

import dbus
import pprint

bus = dbus.SessionBus()
proxy = bus.get_object(
    # Query the Documents search provider...
    'org.gnome.Documents.SearchProvider',
    '/org/gnome/Documents/SearchProvider',

    # Or query my own search provider instead...
    #'org.fedoraproject.fedorapackages.search',
    #'/org/fedoraproject/fedorapackages/search',
)

# which interface do we make our calls against?
kw = dict(dbus_interface="org.gnome.Shell.SearchProvider")

# This is what we want to search our docs for
term = "aw"  # = "foobartest"

ids = proxy.GetInitialResultSet(term, **kw)

result = proxy.GetResultMetas(ids, **kw)
result = [dict(item) for item in result]

pprint.pprint(result)

J5's tool d-feet was indispensable in figuring this out. This dbus-python tutorial was super useful too.

For my own search provider, I forked lmacken's fedmsg-notify as a starting point. More on that later.

View Comments
blog comments powered by Disqus