| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Util functions for git repository processing.""" | 5 """Util functions for git repository processing.""" |
| 6 | 6 |
| 7 import base64 | 7 import base64 |
| 8 import hashlib | 8 import hashlib |
| 9 import json | 9 import json |
| 10 import logging | 10 import logging |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 # TODO(crbug.com/662540): Add unittests. | 55 # TODO(crbug.com/662540): Add unittests. |
| 56 def EnsureDirExists(path): # pragma: no cover | 56 def EnsureDirExists(path): # pragma: no cover |
| 57 directory = os.path.dirname(path) | 57 directory = os.path.dirname(path) |
| 58 if os.path.exists(directory): | 58 if os.path.exists(directory): |
| 59 return | 59 return |
| 60 | 60 |
| 61 os.makedirs(directory) | 61 os.makedirs(directory) |
| 62 | 62 |
| 63 | 63 |
| 64 # TODO(crbug.com/662540): Add unittests. | 64 # TODO(crbug.com/662540): Add unittests. |
| 65 def FlushResult(result, result_path): # pragma: no cover | 65 def FlushResult(result, result_path, serializer=pickle): # pragma: no cover |
| 66 logging.info('\nFlushing results to %s', result_path) | 66 logging.info('\nFlushing results to %s', result_path) |
| 67 EnsureDirExists(result_path) | 67 EnsureDirExists(result_path) |
| 68 with open(result_path, 'wb') as f: | 68 with open(result_path, 'wb') as f: |
| 69 pickle.dump(result, f) | 69 serializer.dump(result, f) |
| 70 | 70 |
| 71 | 71 |
| 72 # TODO(crbug.com/662540): Add unittests. | 72 # TODO(crbug.com/662540): Add unittests. |
| 73 def PrintDelta(deltas, crash_num): # pragma: no cover | 73 def PrintDelta(deltas, crash_num): # pragma: no cover |
| 74 logging.info(('\n+++++++++++++++++++++' | 74 logging.info(('\n+++++++++++++++++++++' |
| 75 '\nDelta on %d crashes ' | 75 '\nDelta on %d crashes ' |
| 76 '\n+++++++++++++++++++++'), crash_num) | 76 '\n+++++++++++++++++++++'), crash_num) |
| 77 | 77 |
| 78 if not deltas: | 78 if not deltas: |
| 79 logging.info('Two sets of results are the same.') | 79 logging.info('Two sets of results are the same.') |
| (...skipping 20 matching lines...) Expand all Loading... |
| 100 for crash_id, delta in deltas.iteritems(): | 100 for crash_id, delta in deltas.iteritems(): |
| 101 delta_str_dict = delta.delta_str_dict | 101 delta_str_dict = delta.delta_str_dict |
| 102 feedback_url = _FEEDBACK_URL_TEMPLATE % crash_id | 102 feedback_url = _FEEDBACK_URL_TEMPLATE % crash_id |
| 103 f.write('%s, "%s", "%s", "%s", "%s"\n' % ( | 103 f.write('%s, "%s", "%s", "%s", "%s"\n' % ( |
| 104 feedback_url, | 104 feedback_url, |
| 105 _EncodeStr(delta_str_dict.get('project', '')), | 105 _EncodeStr(delta_str_dict.get('project', '')), |
| 106 _EncodeStr(delta_str_dict.get('components', '')), | 106 _EncodeStr(delta_str_dict.get('components', '')), |
| 107 _EncodeStr(delta_str_dict.get('cls', '')), | 107 _EncodeStr(delta_str_dict.get('cls', '')), |
| 108 _EncodeStr(delta_str_dict.get('regression_range', '')) | 108 _EncodeStr(delta_str_dict.get('regression_range', '')) |
| 109 )) | 109 )) |
| OLD | NEW |