21 This is from WL#5257 "first API for optimizer trace". 
   24   %s [-q] <a_file> <another_file> <etc> 
   26     -q      quiet mode: only display errors and warnings. 
   28 It will verify that all optimizer traces of files (usually a_file 
   29 is a .result or .reject file which contains 
   30 SELECT * FROM OPTIMIZER_TRACE; ) are JSON-compliant, and that 
   31 they contain no duplicates keys. 
   32 Exit code is 0 if all ok. 
   35 input_files = filter(
lambda x: x != 
'-q', sys.argv[1:]) 
 
   41 quiet = len(input_files) < len(sys.argv) - 1 
 
   45 trace_start_re = re.compile(
r"^.*(\t)?{\n")
 
   46 trace_end_re = re.compile(
r"^}")
 
   47 ignorable_re = re.compile(
r"^.*(ctype_.*|mysqldump)\.result")
 
   49 def check(trace, first_trace_line):
 
   53         parsed = json.loads(s)
 
   55         print "parse error at line", first_trace_line
 
   56         error = str(sys.exc_info())
 
   60         matchobj = re.search(
r"ValueError\('Invalid control character at: line \d+ column \d+ \(char (\d+)\)'", error)
 
   62             first_error_char = int(matchobj.group(1))
 
   63             print s[:first_error_char] + 
"&" + s[first_error_char:]
 
   73     before = s.count(
'"') + s.count(
"'")
 
   74     str_parsed = str(parsed)
 
   75     after = str_parsed.count(
'"') + str_parsed.count(
"'")
 
   77         print "non-unique keys at line %d (%d vs %d)" % (first_trace_line, before, after)
 
   83         print "ok at line", first_trace_line
 
   85 def handle_one_file(name):
 
   86     if ignorable_re.match(name):
 
   89     print "FILE %s" % name
 
   91     all = open(name).readlines()
 
   92     first_trace_line = trace_line = 0
 
   96         if trace_start_re.match(l) 
and first_trace_line == 0:
 
   98             first_trace_line = trace_line
 
  101         if trace_end_re.match(l):
 
  102             assert first_trace_line != 0
 
  104             check(trace, first_trace_line)
 
  106         if first_trace_line != 0:
 
  108             no_comment = re.sub(
"/\*.*\*/", 
"", l)
 
  109             trace.append(no_comment)
 
  113 for f 
in input_files:
 
  117     print >>sys.stderr, 
"Those files have been ignored", ignored
 
  120     print >>sys.stderr, 
"THERE ARE ERRORS"