Sorting package version strings

Interesting less trivial than expected problem (solved): sorting package version numbers:

import re
import rpm

def get_package_version(name):
    """Return version string of installed package."""

    # note: ts can take an argument that is the root of the installation
    #       typically with a var/lib/rpm directory underneath it.
    transaction_set = rpm.ts()

    versions = [header['provideversion'][0]
                for header in transaction_set.dbMatch('name', name)]
    return versions

def version2sortable(version):

    parts = re.split(r'(\d+)', version)
    fields = []
    for part in parts:
            part = int(part)
        except ValueError:
    return tuple(fields)

def cmp_versions(a, b):

    return cmp(version2sortable(a), version2sortable(b))

if __name__ == '__main__':
    print get_package_version('kernel')


['', '', '', '', '']

Note: WordPress is screwing up the markup on the code blocks above. If you have any tips on how to fix this please drop me a line.
Update: Using pre/blockquote hack for now and will try out a code highlighter plug-in when I get the chance. Thanks Tim and Lindsay! :-)

Filed under: fedora,Python — twegener @ 22:04


Preview .deb packages for Exaile for maemo

After much messing around I have build some .deb packages for my Exaile for Maemo port and the mutagen library (one of its dependencies):



There’s lots of work still to be done, but if your desperate for a nicer sound player on the N800 then this should do the job. If there are any features that you would like to be fixed/added sooner rather than later then leave a comment and I’ll push it higher on my todo list.

Filed under: maemo,N800,Python — twegener @ 23:11


Exaile N800 port progress

I shamefully forgot to include a screenshot in the last post, so here you go:

Exaile on N800 screenshot

As you can see, the GUI needs a bit of polishing (‘hildonisation’).

I fixed end-of-track detection for the nokia-mode pipeline. This means that the player will actually start playing the next track in the playlist when a song finishes! The problem was that I neglected to add the playbin bus setup for the nokia pipeline. Also, I had to ensure that the on_message handler was reconnected whenever a new track is played in nokia-mode, since the pipeline gets rebuilt if the file format is different.

The first fix had the pleasant side-effect of making m4a files play correctly from Exaile (previously they were really stuttery).

I fixed the about dialog. The version of libglade on the N800 appears to be a bit behind the times and doesn’t support GtkAboutDialog. I just create it in the program directly using gtk.AboutDialog and it works fine. I’m not a big fan of the libglade approach of reading in the widgets at runtime from an XML file. I prefer the way that it is done in Qt Designer/PyQt where the language-independent XML widget description is converted into Python code in a separate step. This code can be imported and extended by the main application code. It feels like such a waste to add an extra parsing step, for no gain.

I’ve encountered a bit of instability now and then during testing, especially when doing lots of seeking. Sometimes this results in a total lack of responsiveness and I have to kill the process manually. I’m willing to live this for now.

There are plenty of todo items, but I think I’ll work on making a .deb package to enable people to try this out more easily. Also, I plan to start a hildonisation branch, and keep another branch for functionality fixes. I’m using Mercurial for revision control, and this will be a good opportunity to play with branching and merging. Hopefully I will get round to setting up an online repository at some stage.

Related posts:

Filed under: maemo,N800,Python — twegener @ 23:19


Porting Exaile audio player to the Nokia N800

The default media player on the Nokia N800, creatively titled Media Player, sucks in many ways. There is no Ogg Vorbis support, no way to create a playlist from the GUI, seeking support is hit and miss, lacklustre graphic design, minimal metadata support, etc. Its shortcomings are compounded by the fact that is closed source, so it’s not just a matter of fixing the warts. This led me to port an existing media player, Exaile, to the N800.

Exaile is a cross-platform player written in Python. It uses the Gtk GUI framework and GStreamer for the audio backend. It attempts to be a clone of the magnificent Amarok, but in Python (fun to hack and easily portable) and Gtk (handy if that’s what you prefer or is all you have, as on the N800). It has nice collection and playlist management in the the style of Amarok, and some degree of last.fm support.

Porting involved taking out some newer Gtk features (e.g. SVG icons), adding support for the SQLite that comes with Python 2.5 (the version available for Maemo), adding support for modified gstreamer audio codec pipelines, and modifying the GUI to suit the constraints of a handheld platform.

I grabbed the basis for the gstreamer audio pipeline support from the Coherence project; a UPnP platform written in Python, with recently added N800 support. This had support for the built-in MP3 dsp codec as well as the third-party Ogg Vorbis software codec. The parse_launch function is used to create a gstreamer pipeline like so:

player = gst.parse_launch('gnomevfssrc name=source ! id3lib ! dspmp3sink name=sink')

I added support for a couple of other codecs; m4a (MPEG4 audio, so I can play iTunes Plus songs without transcoding degradation) and AAC (advanced audio coding, similar to m4a, used by Nokia). These work in my isolated test cases, but have some problems at the moment when integrated with my Exaile port. It took quite a bit of poking around and trial and error to get m4a playback happening; there’s not a lot of Maemo documentation for this at the moment. For the interested, here are the pipelines:

m4a: gnomevfssrc name=source ! demux3gp ! dspaacsink name=sink sync=false'
aac: gnomevfssrc name=source ! dspaacsink name=sink

I’m still not quite sure of the meaning of the ‘sync=false’ setting, but without that playback is grossly stilted. When used within Exaile playback is still problematic, so there is work to be done there.

The user interface is a bit rough at the moment. It needs to be hildon-ised, to fit in with the look and feel fo the N800 software. I’d also like to integrate some of the pretty aspects of the Listen audio player (another Python/Gtk/Gstreamer audio player) into the interface, and adapt it to suit the style of the N800.

At this point I now have a media player that is better (for me) than the ones that I have used up to this point (Osso Media Player, Kilikali, UKMP, and some other player I removed on account of it trashing some of my setup). There is still a lot of work to be done. Here is my current todo list:

  • Fix the ‘about’ dialog
  • Get .m4a files to play properly
  • Fix displaying of notification bubbles
  • Fix getting available plugins
  • Make left column hidable in main view
  • Improve layout of song info in main view
  • Fix opening of directories in Files browser
  • Fix searching for .aac files
  • Test audio scrobbling
  • Add offline queueing for audio scrobbling
  • Get last.fm streaming working
  • Improve startup time
  • Hildon-ise the GUI
  • Make .deb packages for the exaile port and the mutagen library

This should keep me busy for a while! It is a bit of a nuisance to use at the moment, since it must be started from the command line, and the Mutagen library must be installed by hand. Things will be much nicer once I make .deb pacakges for this. Here is a tarball alpha release for those desperate have a play: exaile_maemo/release/exaile_0.2.9_maemo_5.tar.gz

Filed under: maemo,N800,Python — twegener @ 23:34


Python Books (or not)

Somebody on a mailing list requested suggestions for introductory texts on the Python language. I figured it was worth cross posting my reply here…

I’ve been working with Python regularly for about the last five years. Over that time I haven’t found the need to buy any books on the subject, as there are ample resources online and they tend to be more concise and up to date.

Here is my recommended reading list:

Beyond this, comp.lang.python is a good place to search and ask questions. Especially keep an eye out for posts by any of the ‘bots’: Tim Peters, Alex Martelli, Fredrik Lundh.

Filed under: Python — twegener @ 23:50
Powered by WordPress