Thursday, August 12, 2010


Packagekit is an open source and free suite of software applications designed to provide a consistent and high-level front end for a number of different package management systems. PackageKit itself is a system activated daemon called packagekitd, that abstracts out differences between the different systems. The actual nuts-and-bolts distro tool (yum, apt, conary, etc) is used by PackageKit using compiled and scripted helpers. Those tools (yum, apt, conary, etc) are called the backend for PackageKit. PackageKit isn't meant to replace these tools, instead providing a common set of abstractions that can be used by standard GUI and text mode package managers. It provides C++, python APIs which actually at this currently are not well documented and everything presented here is derived from my studying of the code.


The recent version of PackageKit is 0.6.6, this is not available in repositories and it should be compiled from sources, which can be found here . Please check if newer versions are available. While configuring PackageKit dont forget to configure it with following flags

./configure --with-default-backend=yum --enable-yum --prefix=/usr --sysconfdir=/etc --disable-static --disable-local
sudo make install

PackageKit daemon is a system activated daemon so you have to point dbus the location of the packagekit's daemon by configuring following file


Restart dbus service

sudo /etc/init.d/messagebus restart

PackageKit daemon location is



The attached script failed installing packages with "wetab" user privileges, the reason is not clear yet. That to run script successfully launch it with "sudo".

Raw Dbus API


The DBus API is defined by PackageKit but it's up to the backends themselves to do the right thing, and support all the different ways of using it. Depending on platform/packagekit version Dbus API may differ, for instance Dbus API in Ubuntu for the same version of PackageKit differed from the Dbus API under MeeGo, as authorof PackageKit said "Ubuntu really needs to update PackageKit to something more up to date."


Object path : /org/freedesktop/PackageKit

Interfaces :

  • org.freedesktop.PackageKit
  • org.freedesktop.PackageKit.Transaction

API description can be found here

The latest interface is available in the source tree or on-line.


That to see Dbus API on current platform install Dbus debugger called "d-feet". If after launching "d-feet" does not show /org/freedom/PackageKit object path then launch packagekitd daemon manually with super user privilages: sudo /usr/sbin/packagekitd

Connect to "unix:path=/var/run/dbus/system_bus_socket" to debug SystemBus

High Level Python API

There an python class called "PackageKitClient" located in /usr/lib/python2.6/site-packages/packagekit/ file, which provides high level interface for package management. Unfortunatelly the class is not well documented and some functions are not working OK. Because of this the was implemented, which contains PackageKitClient wrapper class similiar to PackageKitClient implemented in /usr/lib/python2.6/site-packages/packagekit/ file. The is modifcation/addition of Canonicals packagekit wrapper for MeeGo. Run script with superuser privilegies as currently there is an issue decribed in PackageKit installation section.

The PackageKitClient (Attached) Class is written in python and contains methods described below. Also it contains the usage of all described functionalities.

The PackageKitClient class provides following methods:

Resolve(filter, package) : returns list of matched packages

GetDetails(package) : returns the details of the packages

SearchName(filter, name) : searches and returnes availlable packages

InstallPackage(package, )

RemovePackage(package, )

The is attached.

The mechanisms that are used in class for implementing the methods are same for implementing the same methods in C++ as well.

Sample of retrieving Transaction's status using python:

import dbus

bus = dbus.SystemBus()
except dbus.DBusException, e:
print 'Unable to connect to dbus: %s' % str(e)
proxy = bus.get_object('org.freedesktop.PackageKit', '/org/freedesktop/PackageKit')
iface = dbus.Interface(proxy, 'org.freedesktop.PackageKit')
tid = iface.GetTid()

proxy1 = bus.get_object('org.freedesktop.PackageKit', str(tid))
iface1 = dbus.Interface(proxy1, 'org.freedesktop.DBus.Properties')
lst = iface1.Get('org.freedesktop.PackageKit.Transaction', 'Status')
print str(lst)
except dbus.DBusException, e:
print 'Unable to use PackageKit: %s' % str(e)

High Level C++ API, using libpackagekit

The libpackagekit gobject librarywraps the DBUS interface in a nice glib-style API. This makes designing programs that use libpackagekit can concentrate on core functionality rather that the DBUS and PackageKit internals. PkClient in libpackagekit can be used as easily as:

Code sample

PkClient *client;
client = pk_client_new ();
pk_client_install_package (client, "openoffice-clipart");
g_object_unref (client);

More info can be found here

Mechanism of retrieving progress information

The org.freedesktop.PackageKit.Transaction interface containes transaction properties (status, percentage, etc) and signal Changed() which is invoked if one of the parameters is changed. So that to get installation/removal progres just connect to the Changed() signal and read off the properties.

PolicyKit and PackageKit

Running DBus methods like InstallPacakges, RemovePackages, UpdateSystem and others requires authorization with root account. That to change authorization policies for this and other DBus methods PolicyKit should be configured. How to configure PolicyKit can be found in this blog. That to set policy the action name for the appropriate name should be known for example "InstallPackages" methods action name is "org.freedesktop.packagekit.install-untrusted".

Action names can be found the packagekit DBus API description here


Depending on configured policies, platform there might be need to set addtional policies for example that authorize SystemUpdate without root password "sudo" also "org.freedesktop.packagekit.install-untrusted" action should be setResultActive=yes .


That to see the required action names install package "polkit-gnome" which is available in meego repositories. Polkit-gnome will launch a pop-up window if the application requries the autorization.

Under details you can see the action which required authorization.

Here is a sample which shows action name for package removal


No comments:

Post a Comment