OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 | |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """Accumulates EMMA coverage files to produce html output.""" | |
frankf
2013/08/01 19:57:41
Aggregates
gkanwar1
2013/08/07 19:24:56
Done.
| |
8 | |
9 import logging | |
10 import optparse | |
11 import os | |
12 import sys | |
13 | |
14 from pylib import cmd_helper | |
15 from pylib import constants | |
16 | |
17 | |
18 def _GetFilesWithExt(root_dir, ext): | |
19 """Gets all files with a given extension. | |
20 | |
21 Args: | |
22 root_dir: Directory in which to search for files. | |
23 ext: Extension to look for (including dot) | |
24 | |
25 Returns: | |
26 A list of absolute paths to files that match. | |
27 """ | |
28 | |
frankf
2013/08/01 19:57:41
no blank line
gkanwar1
2013/08/07 19:24:56
Done.
| |
29 files = [] | |
30 for root, _, filenames in os.walk(root_dir): | |
31 basenames = [f for f in filenames if os.path.splitext(f)[1] == ext] | |
32 files.extend([os.path.join(root, basename) | |
33 for basename in basenames]) | |
34 | |
35 return files | |
36 | |
37 | |
38 def main(argv): | |
39 option_parser = optparse.OptionParser() | |
40 option_parser.add_option('-o', '--output', help='HTML output filename.') | |
41 option_parser.add_option('-c', '--coverage_dir', default=None, | |
frankf
2013/08/01 19:57:41
- not _
also below
gkanwar1
2013/08/07 19:24:56
Done.
| |
42 help=('Root of the directory in which to search for ' | |
43 'coverage data (.ec) files.')) | |
44 option_parser.add_option('-m', '--metadata_dir', default=None, | |
45 help=('Root of the directory in which to search for ' | |
46 'coverage metadata (.em) files.')) | |
47 options, args = option_parser.parse_args() | |
48 | |
49 if not (options.coverage_dir and options.metadata_dir and options.output): | |
50 option_parser.error('All arguments are required.') | |
51 return constants.ERROR_EXIT_CODE | |
52 | |
53 emma_jar = os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', | |
54 'emma.jar') | |
55 | |
56 coverage_files = _GetFilesWithExt(options.coverage_dir, '.ec') | |
57 metadata_files = _GetFilesWithExt(options.metadata_dir, '.em') | |
58 sources_files = [] | |
59 for f in metadata_files: | |
60 sources_file = os.path.join(os.path.dirname(f), 'emma_sources.txt') | |
61 if os.path.exists(sources_file): | |
62 with open(sources_file, 'r') as f: | |
63 sources_files.extend(f.read().split(' ')) | |
frankf
2013/08/01 19:57:41
can you just split()
gkanwar1
2013/08/07 19:24:56
Good point. That's more robust also.
| |
64 | |
65 input_args = [] | |
66 for f in coverage_files + metadata_files: | |
67 input_args.append('-in') | |
68 input_args.append(f) | |
69 | |
70 output_args = ['-Dreport.html.out.file', options.output] | |
71 source_args = ['-sp', ','.join(sources_files)] | |
72 | |
73 return cmd_helper.RunCmd(['java', '-cp', emma_jar, 'emma', | |
frankf
2013/08/01 19:57:41
align on next line
gkanwar1
2013/08/07 19:24:56
I assume by this you mean to move all args down to
| |
74 'report', '-r', 'html'] | |
75 + input_args + output_args + source_args) | |
76 | |
77 | |
78 if __name__ == '__main__': | |
79 sys.exit(main(sys.argv)) | |
OLD | NEW |