Do you know code that compare versions of debian packages (for example, that knows if 2:23.2.3~rc1-1 is lower than 2:23.2.3-2?), besides dpkg –compare-versions? If yes, please write a comment to this blog post, preferably with a link to the code.
Also, did someone already write a test suite for that? Who would be interested in such a test suite?
I’m considering writing a function in PL/SQL to compare debian versions (for the Ultimate Debian Database project). If someone already wrote that, I’m interested as well.
Dpkg has the code both in C (in lib/vercmp.c, function verrevcmp) and Perl (in scripts/Dpkg/Version.pm). The Perl one is actually just a translation to Perl of the C version, so the algorithm should be identical.
Apt has probably its own version.
The python-debian library has an access point to code comparison for Python, which is actually implemented by python-apt, a binding to libapt.
In the Sodiac project (http://gforge.inria.fr/projects/sodiac/), which contains the various tool of the EDOS toolchain, there is an OCaml implementation of Debian version comparison.
PET (or however it will be finally called) has a Perl module DebianQA::DebVersions
http://wiki.debian.org/Teams/DebianPerlGroup/DebianQA
http://svn.debian.org/viewsvn/pkg-perl/scripts/qa/DebianQA/DebVersions.pm
libapt-pkg implements version comparison as well. You get it by:
#include
Then debVS.CmpVersion(“2:23.2.3~rc1-1”, “2:23.2.3-2”) works like strcmp.
The code is in apt sources, in apt-pkg/deb/debversion.cc
libapt-pkg has also a test case: in the apt sources, it’s in test/versionstest.cc and it uses the data in test/versions.lst
what you include is apt-pkg/debversion.h
Blog softwares with no preview nor a way to edit one’s comments are probably designed to maximise frustration.
Ruby: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=432269
dak (debian archive kit) has an plugin for postgresql doing that (which just links the relevant code from IIRC apt in).
I was told there’s also a python implem in dak
in python-apt:
import apt_pkg
apt_pkg.InitSystem()
apt_pkg.VersionCompare(“1.2”, “1.2~3”)
(use sign of result to check whether version are higher/lower etc.)
I see a few people have mentioned python-apt, which I was unaware of. For a project I worked on I had to do something similar. I wrote my own code from scratch from the debian documentation. You can get the relevant code here: http://repo.or.cz/w/camarabuntu.git?a=blob;f=bin/apt.py;h=f011ac38400bea40213af15a2e49e3d0db25d20f;hb=master