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