Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Im writing a PyGI app where I'd like to show a list of matching applications from the Ubuntu Software Centre in an auto-completion text entry or dropdwon. I haven't yet figured out the best way to present the information, I just want to make it easier for the user to type the name of an application.

But before that, I'd like to figure out how to get the data. Is there an API to get a list of all applications from the Software Centre, or indirectly through the Applications Dash in Unity?

share|improve this question
    
See also askubuntu.com/questions/112004/… for the web API –  David Planella May 25 '12 at 23:34

2 Answers 2

up vote 4 down vote accepted

You can use the xapian DB directly:

import xapian
db=xapian.Database("/var/cache/software-center/xapian")
for m in db.postlist(""): 
    appname = db.get_document(m.docid).get_data()

Or the internal software-center API:

import sys
sys.path.insert(0, "/usr/share/software-center/")
import softwarecenter.db.database
db = softwarecenter.db.database.StoreDatabase()
db._aptcache.open()
# 'use_axi' is use apt-xapian-index
# 'use_agent' is use the Software Center Agent database
db.open(use_axi=False, use_agent=False)
for doc in db:
    app = db.get_application(doc)
    print app.appname, app.pkgname
    appdetails = app.get_details(db)
    # Icon names are relative to /usr/share/app-install/icons/
    print appdetails.icon
share|improve this answer
1  
Michael also tells me: "appdetail has a bunch more, you can get the icon via the normal icon-theme mechanism, but you have to add /usr/share/app-install/icons to the iconpath via append_path()" –  David Planella May 24 '12 at 12:12

Use the package python-apt Install python-apt, there are docs in /usr/share/doc/python-apt

For example to get a list of all installed packages use

import apt
cache = apt.Cache()
installed_packages = [p for p in cache if p.is_installed]

As the Software Centre is written in Python you may want to have a look at its source code as well.

share|improve this answer
    
Thanks, that works well. However, I'm still wondering if I could tap into the data shown in the Applications Lens. That would probably give me the app's icon and would return more relevant results (I believe the Lens shows only apps with a .desktop file, e.g. more user-centric software rather than libraries, CLI software, etc). –  David Planella May 19 '12 at 14:33
    
Have a look at the .desktop files in /usr/share/app-install/desktop –  Florian Diesch May 19 '12 at 15:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.