cov-blame (1171B)
1 #!/usr/bin/python 2 3 import os 4 import re 5 import subprocess 6 import sys 7 8 def handle_file(source_fname, cov_fname): 9 10 lines_blm = subprocess.Popen(["git", "blame", source_fname], stdout=subprocess.PIPE).stdout.readlines() 11 lines_cov = open(cov_fname).readlines() 12 13 # XXXX expensive! 14 while re.match(r'\s*-:\s*0:', lines_cov[0]): 15 del lines_cov[0] 16 17 if len(lines_blm) != len(lines_cov): 18 print >>sys.stderr, "MISMATCH IN NUMBER OF LINES in",source_fname 19 20 for b,c in zip(lines_blm, lines_cov): 21 m = re.match(r'\s*([^\s:]+):', c) 22 if not m: 23 print >>sys.stderr, "CONFUSING LINE %r"% c 24 cov = 'X' 25 elif m.group(1) == '-': 26 cov = '-' 27 elif m.group(1)[0] == '#': 28 cov = '#' 29 elif m.group(1)[0].isdigit(): 30 cov = '1' 31 else: 32 print >>sys.stderr, "CONFUSING LINE %r"% c 33 cov = 'X' 34 35 print cov, b, 36 37 COV_DIR = sys.argv[1] 38 SOURCES = sys.argv[2:] 39 40 for fn in SOURCES: 41 _, base = os.path.split(fn) 42 cfn = os.path.join(COV_DIR, base) 43 cfn += ".gcov" 44 if os.path.exists(cfn): 45 handle_file(fn, cfn) 46 else: 47 print >>sys.stderr, "NO FILE EXISTS CALLED ",cfn 48