From a34cdc40842a0c6613af5633227e8e8166d03367 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Fri, 14 Jul 2006 15:24:01 +0000 Subject: handle prereleases and rc releases properly (From Jason Pepas) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1937 ce84e21b-d406-0410-9b95-82705330c041 --- tools/rpmlisting.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'tools/rpmlisting.py') diff --git a/tools/rpmlisting.py b/tools/rpmlisting.py index 8d9468f12..0bbfd1d14 100644 --- a/tools/rpmlisting.py +++ b/tools/rpmlisting.py @@ -9,7 +9,7 @@ import os import sys import commands import getopt - +import re def run_or_die(command): (status, stdio) = commands.getstatusoutput(command) @@ -35,6 +35,7 @@ def verstr_cmp(a, b): index = 0 a_parts = subdivide(a) b_parts = subdivide(b) + prerelease_pattern = re.compile('rc|pre') while ret == 0 and index < min(len(a_parts), len(b_parts)): subindex = 0 a_subparts = a_parts[index] @@ -45,14 +46,24 @@ def verstr_cmp(a, b): return ret subindex = subindex + 1 if len(a_subparts) != len(b_subparts): - return len(a_subparts) - len(b_subparts) + # handle prerelease special case at subpart level (ie, '4.0.2rc5'). + if len(a_subparts) > len(b_subparts) and prerelease_pattern.match(a_subparts[subindex]): + return -1 + elif len(a_subparts) < len(b_subparts) and prerelease_pattern.match(b_subparts[subindex]): + return 1 + else: + return len(a_subparts) - len(b_subparts) index = index + 1 if len(a_parts) != len(b_parts): - return len(a_parts) - len(b_parts) + # handle prerelease special case at part level (ie, '4.0.2.rc5). + if len(a_parts) > len(b_parts) and prerelease_pattern.match(a_parts[index][0]): + return -1 + elif len(a_parts) < len(b_parts) and prerelease_pattern.match(b_parts[index][0]): + return 1 + else: + return len(a_parts) - len(b_parts) return ret - - def subdivide(verstr): """subdivide takes a version or release string and attempts to subdivide it into components to facilitate sorting. The string is divided into a two level hierarchy of sub-parts. The upper level is subdivided by periods, and the lower level is subdivided by boundaries between digit, alpha, and other character groupings.""" parts = [] -- cgit v1.2.3-1-g7c22