In order to provide a sensible upstream implementation for package query/install/remove methods in Jockey, I started playing with PackageKit and recently packaged and fixed the latest upstream version 0.2.2 work reasonably well on Intrepid.
Unfortunately there are no official Python bindings yet. The raw D-BUS interface is slightly inconvenient to use, since it is fully asynchronous. This seems to be pretty redundant to me, since D-BUS already provides asynchronous method calls (if you need them) and makes writing code painful in synchronous programs.
Thus I went ahead and created a fairly easy Python class for calling the most common PackageKit functions from a Python program (source code), including some demo code.
Now the usage becomes 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, pc, spc, el, rem, c):
print 'install pkg: %s, %i%%, cancel allowed: %s' % (status, pc, str(c))
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.
This just leaves a few nitpicks now, such as PackageKit not being able to determine the package license with Apt, but by and large this provides the basic building blocks now.
Tags: packagekit, programming, python, ubuntu
July 8, 2008 at 16:40 |
Rock on! Can you put this on the packagekit git server please?
July 8, 2008 at 17:42 |
Does this mean we’ll see packagekit in 8,10?
July 8, 2008 at 17:46 |
Will PackageKit be uploaded to Debian?
July 8, 2008 at 18:03 |
@Richard> In fact I wanted to discuss an appropriate place on the mailing list. However, I wasn’t sure whether you would jump at my throat for turning your asynchronous API into a synchronous one again.
(it is the right thing for what I need to do in Jockey).
@anon> Yes, I think we will see PackageKit being used in 8.10, for some applications like Jockey and maybe the language selector. We can’t use it for general package installation yet, since it still lacks debconf/conffile prompt support.
@foo> I don’t know.
July 8, 2008 at 21:52 |
Okay thanks! That would be a good start as it is.
July 11, 2008 at 0:11 |
[...] Martin Pitt’s Weblog addicted to Ubuntu development « Using PackageKit in Python [...]
July 11, 2008 at 5:07 |
[...] for several days now, and it’s driving me up the wall. While a standalone PackageKit client works very well, it completely breaks when I integrate the PackageKit client into my Jockey D-BUS [...]