OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Aggregates EMMA coverage files to produce html output.""" | 7 """Aggregates EMMA coverage files to produce html output.""" |
8 | 8 |
9 import fnmatch | 9 import fnmatch |
10 import json | 10 import json |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import sys | 13 import sys |
| 14 import traceback |
14 | 15 |
15 from pylib import cmd_helper | 16 from pylib import cmd_helper |
16 from pylib import constants | 17 from pylib import constants |
17 | 18 |
18 | 19 |
19 def _GetFilesWithExt(root_dir, ext): | 20 def _GetFilesWithExt(root_dir, ext): |
20 """Gets all files with a given extension. | 21 """Gets all files with a given extension. |
21 | 22 |
22 Args: | 23 Args: |
23 root_dir: Directory in which to search for files. | 24 root_dir: Directory in which to search for files. |
24 ext: Extension to look for (including dot) | 25 ext: Extension to look for (including dot) |
25 | 26 |
26 Returns: | 27 Returns: |
27 A list of absolute paths to files that match. | 28 A list of absolute paths to files that match. |
28 """ | 29 """ |
29 files = [] | 30 files = [] |
30 for root, _, filenames in os.walk(root_dir): | 31 for root, _, filenames in os.walk(root_dir): |
31 basenames = fnmatch.filter(filenames, '*.' + ext) | 32 basenames = fnmatch.filter(filenames, '*.' + ext) |
32 files.extend([os.path.join(root, basename) | 33 files.extend([os.path.join(root, basename) |
33 for basename in basenames]) | 34 for basename in basenames]) |
34 | 35 |
35 return files | 36 return files |
36 | 37 |
37 | 38 |
38 def main(): | 39 def main(argv): |
39 option_parser = optparse.OptionParser() | 40 option_parser = optparse.OptionParser() |
40 option_parser.add_option('--output', help='HTML output filename.') | 41 option_parser.add_option('--output', help='HTML output filename.') |
41 option_parser.add_option('--coverage-dir', default=None, | 42 option_parser.add_option('--coverage-dir', default=None, |
42 help=('Root of the directory in which to search for ' | 43 help=('Root of the directory in which to search for ' |
43 'coverage data (.ec) files.')) | 44 'coverage data (.ec) files.')) |
44 option_parser.add_option('--metadata-dir', default=None, | 45 option_parser.add_option('--metadata-dir', default=None, |
45 help=('Root of the directory in which to search for ' | 46 help=('Root of the directory in which to search for ' |
46 'coverage metadata (.em) files.')) | 47 'coverage metadata (.em) files.')) |
47 option_parser.add_option('--cleanup', action='store_true', | 48 option_parser.add_option('--cleanup', action='store_true', |
48 help=('If set, removes coverage files generated at ' | 49 help=('If set, removes coverage files generated at ' |
49 'runtime.')) | 50 'runtime.')) |
50 options, _ = option_parser.parse_args() | 51 options, args = option_parser.parse_args() |
51 | 52 |
52 if not (options.coverage_dir and options.metadata_dir and options.output): | 53 if not (options.coverage_dir and options.metadata_dir and options.output): |
53 option_parser.error('One or more mandatory options are missing.') | 54 option_parser.error('One or more mandatory options are missing.') |
54 | 55 |
55 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') | 56 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') |
56 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') | 57 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') |
57 print 'Found coverage files: %s' % str(coverage_files) | 58 print 'Found coverage files: %s' % str(coverage_files) |
58 print 'Found metadata files: %s' % str(metadata_files) | 59 print 'Found metadata files: %s' % str(metadata_files) |
59 | 60 |
60 sources = [] | 61 sources = [] |
(...skipping 19 matching lines...) Expand all Loading... |
80 + input_args + output_args + source_args) | 81 + input_args + output_args + source_args) |
81 | 82 |
82 if options.cleanup: | 83 if options.cleanup: |
83 for f in coverage_files: | 84 for f in coverage_files: |
84 os.remove(f) | 85 os.remove(f) |
85 | 86 |
86 return exit_code | 87 return exit_code |
87 | 88 |
88 | 89 |
89 if __name__ == '__main__': | 90 if __name__ == '__main__': |
90 sys.exit(main()) | 91 sys.exit(main(sys.argv)) |
OLD | NEW |