<?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; python</title>
	<atom:link href="http://www.piware.de/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.piware.de</link>
	<description>addicted to Ubuntu development</description>
	<lastBuildDate>Mon, 19 Jul 2010 13:55:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>lpshell &#8211; convenient launchpadlib script</title>
		<link>http://www.piware.de/2010/01/lpshell-convenient-launchpadlib-script/</link>
		<comments>http://www.piware.de/2010/01/lpshell-convenient-launchpadlib-script/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 21:48:01 +0000</pubDate>
		<dc:creator>pitti</dc:creator>
				<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[launchpad]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.piware.de/?p=270</guid>
		<description><![CDATA[These days I often use launchpadlib in my projects for scripting access/modifications in Launchpad. While launchpadlib has quite a good API documentation, this only covers the method calls, not the attributes or collections. So it often takes some poking and trying until you figure out how to access/change things. I found myself typing the same [...]]]></description>
			<content:encoded><![CDATA[<p>These days I often use <a href="https://launchpad.net/launchpadlib">launchpadlib</a> in my projects for scripting access/modifications in Launchpad. While launchpadlib has quite a good <a href="https://launchpad.net/+apidoc/">API documentation</a>, this only covers the method calls, not the attributes or collections. So it often takes some poking and trying until you figure out how to access/change things.</p>
<p>I found myself typing the same things over and over, so I finally wrote a little script called <code>lpshell</code>:</p>
<blockquote><pre>
#!/usr/bin/python -i
import code, os, sys
from launchpadlib.launchpad import Launchpad, STAGING_SERVICE_ROOT, EDGE_SERVICE_ROOT
lp = Launchpad.login_with('test', STAGING_SERVICE_ROOT)
</pre>
</blockquote>
<p>This logs into Launchpad and gives you an interactive Python shell with an &#8220;lp&#8221; object:</p>
<blockquote><pre>
$ lpshell
>>> lp.bugs[439482].duplicate_of
<bug at https://api.staging.launchpad.net/beta/bugs/432598>
</pre>
</blockquote>
<p><strong>Update:</strong> I committed this to ubuntu-dev-tools now, renamed to <code>lp-shell</code> for consistency with the other <code>lp-*</code> commands.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piware.de/2010/01/lpshell-convenient-launchpadlib-script/feed/</wfw:commentRss>
		<slash:comments>7</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>
		<item>
		<title>Asteroids bot submitted, publishing source</title>
		<link>http://www.piware.de/2008/07/asteroids-bot-submitted-publishing-source/</link>
		<comments>http://www.piware.de/2008/07/asteroids-bot-submitted-publishing-source/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 11:10:45 +0000</pubDate>
		<dc:creator>pitti</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[asteroids]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hobby]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://martinpitt.wordpress.com/?p=13</guid>
		<description><![CDATA[A while ago I blogged about my participation in the c&#8217;t programming contest to write a bot that plays against the 1979 Atari console. Submission deadline was June 30th, and the results are trickling in now. I am on rank 104, which I&#8217;m more than satisfied with. Unsurprisingly I didn&#8217;t make the top 50, I [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I blogged about <a href="http://www.piware.de/2008/05/07/my-computer-discovered-playing-games/">my participation in the c&#8217;t programming contest</a> to write a bot that plays against the 1979 Atari console.<br />
Submission deadline was June 30th, and <a href="http://www.heise.de/ct/creativ/08/02/ergebnisse/">the results are trickling in</a> now.</p>
<p>I am on rank 104, which I&#8217;m more than satisfied with. Unsurprisingly I didn&#8217;t make the top 50, I spent way too little time on it. But I had lots of fun with it, I have something that works, and at least outperforms my own Asteroids skills <img src='http://www.piware.de/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>In case anyone is interested in it, the source code is on <a href="http://piware.de/bzr/ct-asteroids/">http://piware.de/bzr/ct-asteroids/</a>. It&#8217;s a bzr branch, so you can <code>bzr get</code> the directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piware.de/2008/07/asteroids-bot-submitted-publishing-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My computer discovered playing games</title>
		<link>http://www.piware.de/2008/05/my-computer-discovered-playing-games/</link>
		<comments>http://www.piware.de/2008/05/my-computer-discovered-playing-games/#comments</comments>
		<pubDate>Wed, 07 May 2008 09:54:35 +0000</pubDate>
		<dc:creator>pitti</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[asteroids]]></category>
		<category><![CDATA[hobby]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://martinpitt.wordpress.com/2008/05/07/my-computer-discovered-playing-games/</guid>
		<description><![CDATA[The other day I read about the current c&#8217;t programming contest and got addicted immediately. The task is to create a program which plays the Atari Asteroids game from 1979: Unfortunately they do not send that gem to everyone , but they do send the original 8 KB of ROM, so you can play it [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I read about the current <a href="http://www.heise.de/ct/projekte/machmit/asteroids/">c&#8217;t programming contest</a> and got addicted immediately. The task is to create a program which plays the Atari Asteroids game from 1979:</p>
<p><img src="http://www.heise.de/ct/creativ/08/bilder/asteroids.jpg" alt="" /></p>
<p>Unfortunately they do not send that gem to everyone <img src='http://www.piware.de/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> , but they do send the original 8 KB of ROM, so you can play it on the <a href="http://mamedev.org/">MAME emulator</a>.</p>
<p><img src="http://www.heinzwerner.de/emu_asteroids.jpg" alt="" /></p>
<p>So far I got the emulator and the game running, and have a Python script which tracks the objects and their velocity vectors. I spent half of the weekend doing the vector analysis bits with good old pencil and paper. Reviving all the maths bits from school (about 11 years ago) was a lot of fun! Now I have useful formulas for determining the shooting angle to hit a moving comet from a moving and decelerating ship, determining if and when two moving objects with given radius collide, etc. In my head I have a first cut of a strategy, too.</p>
<p>Now I just need to find some time to actually implement all of this&#8230;</p>
<p>Once the contest is over, I&#8217;ll publish my sources, in case anyone else is interested.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piware.de/2008/05/my-computer-discovered-playing-games/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Python code coverage</title>
		<link>http://www.piware.de/2008/04/python-code-coverage/</link>
		<comments>http://www.piware.de/2008/04/python-code-coverage/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 14:39:01 +0000</pubDate>
		<dc:creator>pitti</dc:creator>
				<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[jockey]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://martinpitt.wordpress.com/?p=6</guid>
		<description><![CDATA[Today I was playing with python-coverage, which seems to be the tool of choice for code coverage measurement in Python. Since I am constantly hacking on Jockey&#8217;s test suite, I want to strive for perfection and cover everything, so it does sound like something worthwhile. First I tried to use it like documented: python /usr/share/python-support/python-coverage/coverage.py [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was playing with python-coverage, which seems to be the tool of choice for code coverage measurement in Python. Since I am constantly hacking on Jockey&#8217;s test suite, I want to strive for perfection and cover everything, so it does sound like something worthwhile.</p>
<p>First I tried to use it like documented:</p>
<blockquote><p><code>python /usr/share/python-support/python-coverage/coverage.py -x tests/run</code></p></blockquote>
<p>which just caused the tests not to run at all, for no immediately obvious reason (it worked fine with real Python modules in apport). However, it gets much nicer once you stop trying to wrap it around the command line call and start to integrate it into the test suite code itself:</p>
<blockquote><p><code>import coverage<br />
coverage.erase()<br />
coverage.exclude('raise NotImplementedError')<br />
coverage.start()</code></p>
<p>[... run all the tests ... ]</p>
<p>coverage.stop()<br />
coverage.report(glob(&#8216;jockey/*.py&#8217;))<br />
coverage.report(glob(&#8216;examples/handlers/*.py&#8217;))<br />
coverage.erase()</p></blockquote>
<p>(which is more or less what I <a href="http://bazaar.launchpad.net/~jockey-hackers/jockey/trunk/revision/266">committed</a>).</p>
<p>This will run all the tests, and give me a report about how much code they covered, plus a list of code lines which weren&#8217;t touched. For example:</p>
<blockquote><p><code>Name                 Stmts   Exec  Cover   Missing<br />
jockey/handlers        248    242    97%   402-405, 420-421, 514<br />
</code></p></blockquote>
<p>Also, the exclude() interface is much more flexible than putting #pragmas all over the place (which do not seem to really work anyway unfortunately).</p>
<p>Now, off to fixing everything to get 100%. I was surprised how many little bugs I found and fixed while completing the tests. Test suites FTW!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piware.de/2008/04/python-code-coverage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
