aboutsummaryrefslogtreecommitdiffstats
path: root/mcstrans/share/util/mlscolor-test
blob: 03fc4be40375e9a8de868d15b8d4cc608bbe4d48 (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
#!/usr/bin/python -E
import sys
import selinux


verbose = 0
errors = 0

if len(sys.argv) > 1 and sys.argv[1] == "-v":
    verbose = 1

for arg in sys.argv[1:]:
    f = open(arg, 'r')
    for line in f:
        if line.startswith('#'):
            continue
        if not line.strip():
            continue
        line = line.rstrip('\n')
#       print line
        context, expected = line.split("=")
        rc, raw = selinux.selinux_trans_to_raw_context(context)
        if rc < 0:
            print("Unable to get raw context of '%s'" % (context))
            errors += 1
            continue
        rc, colors = selinux.selinux_raw_context_to_color(raw)
        if rc < 0:
            print("Unable to get colors for '%s'" % (context))
            errors += 1
            continue
        colors = colors.rstrip()
        if colors != expected:
            print("For '%s' got\n\t'%s' expected\n\t'%s'" % (context, colors, expected))
            errors += 1
            continue
    f.close()

s = "s"
if errors == 1:
    s = ""
print("mlscolor-test done with %d error%s" % (errors, s))

sys.exit(errors)