1#!/usr/bin/python3 -E 2import sys 3import selinux 4 5 6verbose = 0 7errors = 0 8 9if len(sys.argv) > 1 and sys.argv[1] == "-v": 10 verbose = 1 11 12for arg in sys.argv[1:]: 13 f = open(arg, 'r') 14 for line in f: 15 if line.startswith('#'): 16 continue 17 if not line.strip(): 18 continue 19 line = line.rstrip('\n') 20# print line 21 context, expected = line.split("=") 22 rc, raw = selinux.selinux_trans_to_raw_context(context) 23 if rc < 0: 24 print("Unable to get raw context of '%s'" % (context)) 25 errors += 1 26 continue 27 rc, colors = selinux.selinux_raw_context_to_color(raw) 28 if rc < 0: 29 print("Unable to get colors for '%s'" % (context)) 30 errors += 1 31 continue 32 colors = colors.rstrip() 33 if colors != expected: 34 print("For '%s' got\n\t'%s' expected\n\t'%s'" % (context, colors, expected)) 35 errors += 1 36 continue 37 f.close() 38 39s = "s" 40if errors == 1: 41 s = "" 42print("mlscolor-test done with %d error%s" % (errors, s)) 43 44sys.exit(errors) 45