File: versiontest.py

package info (click to toggle)
python-apt 0.7.100.1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,748 kB
  • ctags: 1,919
  • sloc: cpp: 8,937; python: 5,750; makefile: 89; sh: 9
file content (39 lines) | stat: -rwxr-xr-x 1,127 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python

# This is a simple clone of tests/versiontest.cc
import apt_pkg
import sys
import re

apt_pkg.InitConfig()
apt_pkg.InitSystem()

TestFile = apt_pkg.ParseCommandLine(apt_pkg.Config, [], sys.argv)
if len(TestFile) != 1:
    print "Must have exactly 1 file name"
    sys.exit(0)

# Go over the file..
List = open(TestFile[0], "r")
CurLine = 0
while(1):
    Line = List.readline()
    CurLine = CurLine + 1
    if Line == "":
        break
    Line = Line.strip()
    if len(Line) == 0 or Line[0] == '#':
        continue

    Split = re.split("[ \n]", Line)

    # Check forward
    if apt_pkg.VersionCompare(Split[0], Split[1]) != int(Split[2]):
        print "Comparision failed on line %u. '%s' ? '%s' %i != %i" % (CurLine,
            Split[0], Split[1], apt_pkg.VersionCompare(Split[0], Split[1]),
            int(Split[2]))
    # Check reverse
    if apt_pkg.VersionCompare(Split[1], Split[0]) != -1 * int(Split[2]):
        print "Comparision failed on line %u. '%s' ? '%s' %i != %i" % (CurLine,
            Split[1], Split[0], apt_pkg.VersionCompare(Split[1], Split[0]),
            -1 * int(Split[2]))