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.
#1 by Richard Hughes on 2008/07/08 - 16:40
Zitieren
Rock on! Can you put this on the packagekit git server please?
#2 by anon on 2008/07/08 - 17:42
Zitieren
Does this mean we’ll see packagekit in 8,10?
#3 by foo on 2008/07/08 - 17:46
Zitieren
Will PackageKit be uploaded to Debian?
#4 by martinpitt on 2008/07/08 - 18:03
Zitieren
@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.
#5 by anon on 2008/07/08 - 21:52
Zitieren
Okay thanks! That would be a good start as it is.
Pingback: Argh dbus-python « Martin Pitt’s Weblog
Pingback: Install & Use Ubuntu » Blog Archive » Martin Pitt: Argh dbus-python