Re: How to bet back to a sane version number?
Hi,
Frank Küster <frank@debian.org> wrote:
> And what would be "as needed", for those who never used apt-python or
> even Python at all? Here's my first Python script:
When you don't understand, try it interactively from the Python
interpreter:
% python
Python 2.4.4 (#2, Apr 5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import apt_pkg
>>> apt_pkg.init()
>>> def compare(a, b):
... apt_pkg.VersionCompare(a, b)
...
>>> compare("4.22.3","4.22.4")
>>>
[...]
> def compare(a, b):
> apt_pkg.VersionCompare(a, b)
This function doesn't return anything (well, actually, it returns the
object None). The correct version is:
def compare(a, b):
return apt_pkg.VersionCompare(a, b)
> if compare("4.22.3","4.22.4"):
> print 'true if second is larger'
> else:
> print 'false if second is larger'
>
> if compare("4.22.4","4.22.3"):
> print 'true if first is larger'
> else:
> print 'false if first is larger'
This doesn't work because apt_pkg.VersionCompare() doesn't return a
boolean (neither as an integer, nor as an object of type 'bool' as are
True and False).
apt_pkg.VersionCompare(a, b) < 0 when a < b
apt_pkg.VersionCompare(a, b) = 0 when a = b
apt_pkg.VersionCompare(a, b) > 0 when a > b
So, you have to test the sign of the result, not whether it is zero or
non-zero (which is what happens when an integer is interpreted as a
boolean).
--
Florent
Reply to: