summaryrefslogtreecommitdiffstats
path: root/gluster/swift/common/middleware/gswauth/swauth/swift_version.py
blob: cabe284e27be24d7c352b4c981935e5517450a7f (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import swift


MAJOR = None
MINOR = None
REVISION = None
FINAL = None


def parse(value):
    parts = value.split('.')
    if parts[-1].endswith('-dev'):
        final = False
        parts[-1] = parts[-1][:-4]
    else:
        final = True
    major = int(parts.pop(0))
    minor = int(parts.pop(0))
    if parts:
        revision = int(parts.pop(0))
    else:
        revision = 0
    return major, minor, revision, final


def newer_than(value):
    global MAJOR, MINOR, REVISION, FINAL
    major, minor, revision, final = parse(value)
    if MAJOR is None:
        MAJOR, MINOR, REVISION, FINAL = parse(swift.__version__)
    if MAJOR < major:
        return False
    elif MAJOR == major:
        if MINOR < minor:
            return False
        elif MINOR == minor:
            if REVISION < revision:
                return False
            elif REVISION == revision:
                if not FINAL or final:
                    return False
    return True


def run_tests():
    global MAJOR, MINOR, REVISION, FINAL
    MAJOR, MINOR, REVISION, FINAL = parse('1.3')
    assert(newer_than('1.2'))
    assert(newer_than('1.2.9'))
    assert(newer_than('1.3-dev'))
    assert(newer_than('1.3.0-dev'))
    assert(not newer_than('1.3'))
    assert(not newer_than('1.3.0'))
    assert(not newer_than('1.3.1-dev'))
    assert(not newer_than('1.3.1'))
    assert(not newer_than('1.4'))
    assert(not newer_than('2.0'))
    MAJOR, MINOR, REVISION, FINAL = parse('1.7.7-dev')
    assert(newer_than('1.6'))
    assert(newer_than('1.7'))
    assert(newer_than('1.7.6-dev'))
    assert(newer_than('1.7.6'))
    assert(not newer_than('1.7.7'))
    assert(not newer_than('1.7.8-dev'))
    assert(not newer_than('1.7.8'))
    assert(not newer_than('1.8.0'))
    assert(not newer_than('2.0'))


if __name__ == '__main__':
    run_tests()