OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Compare the artifacts from two builds.""" | 5 """Compare the artifacts from two builds.""" |
6 | 6 |
7 import json | 7 import json |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 79 |
80 max_filepath_len = max(len(n) for n in first_list & second_list) | 80 max_filepath_len = max(len(n) for n in first_list & second_list) |
81 for f in sorted(first_list & second_list): | 81 for f in sorted(first_list & second_list): |
82 first_file = os.path.join(first_dir, f) | 82 first_file = os.path.join(first_dir, f) |
83 second_file = os.path.join(second_dir, f) | 83 second_file = os.path.join(second_dir, f) |
84 files_diffs = compare_files(first_file, second_file) | 84 files_diffs = compare_files(first_file, second_file) |
85 if not files_diffs: | 85 if not files_diffs: |
86 result = 'equal' | 86 result = 'equal' |
87 else: | 87 else: |
88 file_len = os.stat(first_file).st_size | 88 file_len = os.stat(first_file).st_size |
89 difference = ('different size' if result == -1 else | 89 difference = ('different size' if files_diffs == -1 else |
M-A Ruel
2014/10/31 20:16:58
I'd go all the way while at it;
if files_diffs ==
| |
90 '%d out of %d bytes are different (%.2f%%)' % | 90 '%d out of %d bytes are different (%.2f%%)' % |
91 (files_diffs, file_len, 100.0 * files_diffs / file_len)) | 91 (files_diffs, file_len, 100.0 * files_diffs / file_len)) |
92 result = 'DIFFERENT: %s' % difference | 92 result = 'DIFFERENT: %s' % difference |
93 res += 1 | 93 res += 1 |
94 print('%-*s: %s' % (max_filepath_len, f, result)) | 94 print('%-*s: %s' % (max_filepath_len, f, result)) |
95 | 95 |
96 print '%d files are equal, %d are different.' % ( | 96 print '%d files are equal, %d are different.' % ( |
97 len(first_list & second_list) - res, res) | 97 len(first_list & second_list) - res, res) |
98 | 98 |
99 return 0 if res == 0 else 1 | 99 return 0 if res == 0 else 1 |
100 | 100 |
101 | 101 |
102 def main(): | 102 def main(): |
103 parser = optparse.OptionParser(usage='%prog [options]') | 103 parser = optparse.OptionParser(usage='%prog [options]') |
104 parser.add_option('--first-build-dir', help='The first build directory.') | 104 parser.add_option('--first-build-dir', help='The first build directory.') |
105 parser.add_option('--second-build-dir', help='The second build directory.') | 105 parser.add_option('--second-build-dir', help='The second build directory.') |
106 options, _ = parser.parse_args() | 106 options, _ = parser.parse_args() |
107 | 107 |
108 if not options.first_build_dir: | 108 if not options.first_build_dir: |
109 parser.error('--first-build-dir is required') | 109 parser.error('--first-build-dir is required') |
110 if not options.second_build_dir: | 110 if not options.second_build_dir: |
111 parser.error('--second-build-dir is required') | 111 parser.error('--second-build-dir is required') |
112 | 112 |
113 return compare_build_artifacts(options.first_build_dir, | 113 return compare_build_artifacts(options.first_build_dir, |
114 options.second_build_dir) | 114 options.second_build_dir) |
115 | 115 |
116 | 116 |
117 if __name__ == '__main__': | 117 if __name__ == '__main__': |
118 sys.exit(main()) | 118 sys.exit(main()) |
OLD | NEW |