[packagekit] Synchronous Python interface

Martin Pitt martin.pitt at ubuntu.com
Tue Jul 8 09:27:47 PDT 2008


Hi all,

in my current driver search/UI project "Jockey" [1] I want to provide
a sensible upstream implementation for package query/install/remove
methods, so I started intregrating PackageKit support (since it now
works on Ubuntu Intrepid).

The raw D-BUS interface is slightly inconvenient to use for me, since
it is fully asynchronous. For my purposes (package installation etc.
happens in the jockey backend, frontends communicate with it through
the system D-BUS), this is pretty redundant to me, since D-BUS already
provides asynchronous method calls, and otherwise the Jockey backend
is using a synchronous style.

Thus I went ahead and created a fairly easy Python class for calling
the most common PackageKit functions from a Python program,
including some demo code.

The usage is fairly simple:

    pk = PackageKitClient()

    print pk.Resolve('none', 'pmount')
    # [(False, 'pmount;0.9.17-2;amd64;Ubuntu', 'mount removable devices as normal user')]

    print pk.GetDetails(’installation-guide-powerpc;20080520ubuntu1;all;Ubuntu’)
    # (’unknown’, ‘unknown’, ‘This package contains the Ubuntu installation guide \
    # for the PowerPC architecture, in a variety of languages.\nA shorter reference, \
    # the installation HOWTO, is included in an appendix. ‘, ”, 1074334)

    def cb(status, percent, subpercent, elapsed, remaining, cancel_allowed):
        print 'install pkg: %s, %i%%, cancel allowed: %s' % (status, percent, str(cancel_allowed))
        return True # return False to cancel
    pk.InstallPackages(['pmount;0.9.17-2;i386;Ubuntu', 'quilt;0.46-6;all;Ubuntu'], cb)

As usual in Python, errors are represented as exceptions.

It's not a complete binding yet, so far just a "WorksForMe" thing.
However, it might be useful for other people as well.

I welcome any suggestions how to improve it, or LARTing why
asynchronous APIs are better :-P

Martin

[1] http://launchpad.net/jockey

-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: packagekit-wrapper.py
Type: text/x-python
Size: 9023 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/packagekit/attachments/20080708/b3343f04/attachment-0004.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.freedesktop.org/archives/packagekit/attachments/20080708/b3343f04/attachment-0004.pgp>


More information about the PackageKit mailing list