[Mageia-dev] [soft-commits] [3012] Add ability to increase the version number of a given package

Thierry Vignaud thierry.vignaud at gmail.com
Wed Feb 22 18:13:12 CET 2012


On 22 February 2012 17:06,  <root at mageia.org> wrote:
> Revision 3012 Author ovitters Date 2012-02-22 17:06:51 +0100 (Wed, 22 Feb
> 2012)
>
> Log Message
>
> Add ability to increase the version number of a given package
>
> Command tries to be careful and does various checks (patches still apply,
> etc)

Too sad it doesn't support this:
  %define rel 3
  %define release %mkrel %rel
(which is hard anyway and should be rare though it does exist among
mga packages)

> +def version_cmp(a, b):
> +    """Compares two versions
> +
> +    Returns
> +      -1 if a < b
> +      0  if a == b
> +      1  if a > b
> +
> +    Logic from Bugzilla::Install::Util::vers_cmp"""
> +    A = re_version.findall(a.lstrip('0'))
> +    B = re_version.findall(b.lstrip('0'))
> +
> +    while A and B:
> +        a = A.pop(0)
> +        b = B.pop(0)
> +
> +        if a == b:
> +            continue
> +        elif a == '-':
> +            return -1
> +        elif b == '-':
> +            return 1
> +        elif a == '.':
> +            return -1
> +        elif b == '.':
> +            return 1
> +        elif a.isdigit() and b.isdigit():
> +            c = cmp(a, b) if (a.startswith('0') or b.startswith('0')) else
> cmp(int(a, 10), int(b, 10))
> +            if c:
> +                return c
> +        else:
> +            c = cmp(a.upper(), b.upper())
> +            if c:
> +                return c
> +
> +    return cmp(len(A), len(B))

Please do not reinvent the whell and do sg like this instead:

import rpm

def compare(t1, t2):
   # t1 and t2 are tuples of (version, release)
    v1, r1 = t1
    v2, r2 = t2
    return rpm.labelCompare(('1', v1, r1), ('1', v2, r2))


More information about the Mageia-dev mailing list