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
|
import os
import re
import optparse
PACKAGE_REGEX = re.compile(r'^\s*package\s+(.*?);', flags=re.MULTILINE | re.DOTALL)
def parse_args():
parser = optparse.OptionParser()
parser.add_option('-o', '--output')
parser.add_option('-a', '--source-root', dest='source_root')
return parser.parse_args()
def get_package_name(filename):
with open(filename) as afile:
match = PACKAGE_REGEX.search(afile.read())
if match:
return match.group(1).replace('\n\t ', '').replace('.', '/')
return ''
def write_coverage_sources(output, srcroot, files):
with open(output, 'w') as afile:
for filename in files:
pname = get_package_name(os.path.join(srcroot, filename))
afile.write(os.path.join(pname, os.path.basename(filename)) + ':' + filename + '\n')
def main():
opts, files = parse_args()
write_coverage_sources(opts.output, opts.source_root, files)
if __name__ == '__main__':
exit(main())
|