How to programmatically fetch a list of applications from the Software Center
Solution 1:
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
Solution 2:
Use the package 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.