#!/usr/bin/python
'''

Usage: checktags [ file ]

Compare a table of 

package  old_version new_version
...

and check if any old_version is larger than new_version.
This can directly process the output of diff_releases.
'''

from __future__ import print_function
import sys
import re

regex = re.compile("[^-]*-(\d+)-(\d+)-(\d+)(-(\d+))?")

for line in (len(sys.argv) > 1 and open(sys.argv[1]) or sys.stdin).readlines():
    try:
        line = line.strip()
        package, old, new = line.split()
        if old == "-------------------"  or new == "-------------------" :  continue

        v1 = re.match(regex, old)
        if not v1: 
            print("Version for ",package, old)
            continue

        v2 = re.match(regex, new)
        if not v2: 
            print("Version for ",package, new)
            continue

        ver1 = v1.group(1,2,3)
        patch1 = v1.lastindex > 4 and int(v1.group(5)) or 0
        num1 = int(ver1[0]) * 1000000 + int(ver1[1]) * 10000 + int(ver1[2]) * 100 + patch1

        ver2 = v2.group(1,2,3)
        patch2 = v2.lastindex > 4 and int(v2.group(5)) or 0
        num2 = int(ver2[0]) * 1000000 + int(ver2[1]) * 10000 + int(ver2[2]) * 100 + patch2

        if num1 > num2:
            print(package,old,new)

    except Exception as ex:
        if line == 'felixbus' or line == 'netio': continue
        print(ex,':',line)
