<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Martin Pitt &#187; packagekit</title>
	<atom:link href="http://www.piware.de/tag/packagekit/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.piware.de</link>
	<description>addicted to Ubuntu development</description>
	<lastBuildDate>Fri, 03 Feb 2012 07:03:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>PackageKit/aptdaemon &#8220;what-provides&#8221; plugin support</title>
		<link>http://www.piware.de/2012/02/packagekitaptdaemon-what-provides-plugin-support/</link>
		<comments>http://www.piware.de/2012/02/packagekitaptdaemon-what-provides-plugin-support/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 07:03:48 +0000</pubDate>
		<dc:creator>pitti</dc:creator>
				<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[announcement]]></category>
		<category><![CDATA[apt]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[packagekit]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.piware.de/?p=586</guid>
		<description><![CDATA[PackageKit has a &#8220;WhatProvides&#8221; API for mapping distribution independent concepts to particular package names. For example, you could ask &#8220;which packages provide a decoder for AC3 audio files? $ pkcon what-provides "gstreamer0.10(decoder-audio/ac3)" [...] Installed gstreamer0.10-plugins-good-0.10.30.2-2ubuntu2.amd64 GStreamer plugins from the "good" set Available gstreamer0.10-plugins-ugly-0.10.18-3ubuntu4.amd64 GStreamer plugins from the "ugly" set This is the kind of question [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.packagekit.org/">PackageKit</a> has a &#8220;WhatProvides&#8221; API for mapping distribution independent concepts to particular package names. For example, you could ask &#8220;which packages provide a decoder for AC3 audio files?</p>
<pre>
$ pkcon what-provides  "gstreamer0.10(decoder-audio/ac3)"
[...]
Installed   	gstreamer0.10-plugins-good-0.10.30.2-2ubuntu2.amd64	GStreamer plugins from the "good" set
Available  	gstreamer0.10-plugins-ugly-0.10.18-3ubuntu4.amd64	GStreamer plugins from the "ugly" set
</pre>
<p>This is the kind of question your video player would ask the system if it encounters a video it cannot play. In reality they of course use the D-BUS or the library API, but it&#8217;s easier to demonstrate with the PackageKit command line client.</p>
<p>PackageKit <a href="https://gitorious.org/packagekit/packagekit/blobs/master/docs/provides-component-naming.txt">provides a fair number of those concepts</a>; I recently added <a href="https://gitorious.org/packagekit/packagekit/commit/0c6db3f2118dbb723529b24af11a136d19900244">LANGUAGE_SUPPORT</a> for packages which provide dictionaries, spell checkers, and other language support for a given language or locale code.</p>
<p>However, PackageKit&#8217;s apt backend does not actually implement a lot of these (only CODEC and MODALIAS), and aptdaemons&#8217;s PackageKit compatibility API does not implement any. That might be because their upstreams do not know enough how to do the mapping for a particular distro/backend, because doing so involves distro specific code which should not go into upstreams, or simply because of the usual chicken-egg problem of app developers rather doing their own thing instead of using generic APIs.</p>
<p>So this got discussed between Sebastian Heinlein and me, and voila, <a href="https://gitorious.org/packagekit/packagekit/commit/b516f18e28c708d31f0a85b35ca3ec47fb3bd16c">there it is</a>: it is now very easy to provide Python plugins for &#8220;what-provides&#8221; to implement any of the existing types. For example, <a href="https://launchpad.net/ubuntu/+source/language-selector/+changelog">language-selector</a> now ships a plugin which implements LANGUAGE_SUPPORT, so you can ask &#8220;which packages do I need for Chinese in China&#8221; (i. e. simplified Chinese)?</p>
<pre>
$ pkcon what-provides "locale(zh_CN)"
[...]
Available   	firefox-locale-zh-hans-10.0+build1-0ubuntu1.all	Simplified Chinese language pack for Firefox
Available   	ibus-sunpinyin-2.0.3-2.amd64            	sunpinyin engine for ibus
Available   	language-pack-gnome-zh-hans-1:12.04+20120130.all	GNOME translation updates for language Simplified Chinese
Available   	ttf-arphic-ukai-0.2.20080216.1-1.all    	"AR PL UKai" Chinese Unicode TrueType font collection Kaiti style
[...]
</pre>
<p><a href="http://blogs.gnome.org/rodrigo/">Rodrigo Moya</a> is currently working on implementing the <a href="https://live.gnome.org/Design/SystemSettings/RegionAndLanguage">control-center region panel redesign</a> in a <a href="http://git.gnome.org/browse/gnome-control-center/log/?h=wip/install-languages">branch</a>. This uses exactly this feature.</p>
<p>In Ubuntu we usually do not use PackageKit itself, but aptdaemon and its PackageKit API compatibility shim <code>python-aptdaemon.pkcompat</code>. So I <a href="http://bazaar.launchpad.net/~aptdaemon-developers/aptdaemon/main/revision/769">ported that plugin support</a> for aptdaemon-pkcompat as well, so plugins work with either now. Ubuntu Precise got the new aptdaemon (0.43+bzr769-0ubuntu1) and language-selector (0.63) versions today, so you can start playing around with this now.</p>
<p>So how can you write your own plugins? This is a trivial, although rather nonsense example:</p>
<pre>
from packagekit import enums

def my_what_provides(apt_cache, provides_type, search):
    if provides_type in (enums.PROVIDES_CODEC, enums.PROVIDES_ANY):
        return [apt_cache["gstreamer-moo"]]
    else:
        raise NotImplementedError('cannot handle type ' + str(provides_type))
</pre>
<p>The function gets an <code>apt.Cache</code> object, one of <code>enums.PROVIDES_*</code> and the actual search type as described <a href="https://gitorious.org/packagekit/packagekit/blobs/master/docs/provides-component-naming.txt">in the documentation</a> (above dummy example does not actually use it). It then decides whether it can handle the request and return a list of <code>apt.package.Package</code> objects (i. e. values in an <code>apt.Cache</code> map), or raise a <code>NotImplementedError</code> otherwise.</p>
<p>You register the plugin through Python pkg-resources in your setup.py (this needs setuptools):</p>
<pre>
   setup(
       [....]

       entry_points="""[packagekit.apt.plugins]
what_provides=my_plugin_module_name:my_what_provides
""",
       [...])
</pre>
<p>You can register arbitrarily many plugins, they will be all called and their resulting package lists joined.</p>
<p>All this will hopefully help a bit to push distro specifics to the lowest possible levels, and use upstream friendly and distribution agnostic APIs in your applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piware.de/2012/02/packagekitaptdaemon-what-provides-plugin-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PackageKit in Python</title>
		<link>http://www.piware.de/2008/07/calling-packagekit-from-python-programs/</link>
		<comments>http://www.piware.de/2008/07/calling-packagekit-from-python-programs/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 14:10:35 +0000</pubDate>
		<dc:creator>pitti</dc:creator>
				<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[packagekit]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://martinpitt.wordpress.com/?p=14</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>In order to provide a sensible upstream implementation for package query/install/remove methods in Jockey, I started playing with <a href="http://www.packagekit.org/">PackageKit</a> and recently packaged and fixed the latest upstream version 0.2.2 work reasonably well on Intrepid.</p>
<p>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.</p>
<p>Thus I went ahead and created a fairly easy Python class for calling the most common PackageKit functions from a Python program (<a href="http://people.canonical.com/~pitti/scripts/packagekit-wrapper.py">source code</a>), including some demo code.</p>
<p>Now the usage becomes fairly simple:</p>
<pre>    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)</pre>
<p>As usual in Python, errors are represented as exceptions.</p>
<p>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.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piware.de/2008/07/calling-packagekit-from-python-programs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

