| 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 for delta test.""" | 5 """Util functions for git repository processing for delta test.""" |
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 ['git', 'rev-parse', revision]).replace('\n', '') | 49 ['git', 'rev-parse', revision]).replace('\n', '') |
| 50 except: # pylint: disable=W | 50 except: # pylint: disable=W |
| 51 logging.error('Failed to parse git hash for %s\nStacktrace:\n%s', | 51 logging.error('Failed to parse git hash for %s\nStacktrace:\n%s', |
| 52 revision, traceback.format_exc()) | 52 revision, traceback.format_exc()) |
| 53 return None | 53 return None |
| 54 | 54 |
| 55 | 55 |
| 56 # TODO(crbug.com/662540): Add unittests. | 56 # TODO(crbug.com/662540): Add unittests. |
| 57 def EnsureDirExists(path): # pragma: no cover | 57 def EnsureDirExists(path): # pragma: no cover |
| 58 directory = os.path.dirname(path) | 58 directory = os.path.dirname(path) |
| 59 # TODO: this has a race condition. Should ``try: os.makedirs`` instead, |
| 60 # discarding the error and returning if the directory already exists. |
| 59 if os.path.exists(directory): | 61 if os.path.exists(directory): |
| 60 return | 62 return |
| 61 | 63 |
| 62 os.makedirs(directory) | 64 os.makedirs(directory) |
| 63 | 65 |
| 64 | 66 |
| 65 # TODO(crbug.com/662540): Add unittests. | 67 # TODO(crbug.com/662540): Add unittests. |
| 66 def FlushResult(result, result_path, serializer=pickle): # pragma: no cover | 68 def FlushResult(result, result_path, serializer=pickle): # pragma: no cover |
| 67 print '\nFlushing results to', result_path | 69 print '\nFlushing results to', result_path |
| 68 EnsureDirExists(result_path) | 70 EnsureDirExists(result_path) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 for crash_id, delta in deltas.iteritems(): | 102 for crash_id, delta in deltas.iteritems(): |
| 101 delta_str_dict = delta.delta_str_dict | 103 delta_str_dict = delta.delta_str_dict |
| 102 feedback_url = _FRACAS_FEEDBACK_URL_TEMPLATE % (app_id, crash_id) | 104 feedback_url = _FRACAS_FEEDBACK_URL_TEMPLATE % (app_id, crash_id) |
| 103 f.write('%s, "%s", "%s", "%s", "%s"\n' % ( | 105 f.write('%s, "%s", "%s", "%s", "%s"\n' % ( |
| 104 feedback_url, | 106 feedback_url, |
| 105 _EncodeStr(delta_str_dict.get('suspected_project', '')), | 107 _EncodeStr(delta_str_dict.get('suspected_project', '')), |
| 106 _EncodeStr(delta_str_dict.get('suspected_components', '')), | 108 _EncodeStr(delta_str_dict.get('suspected_components', '')), |
| 107 _EncodeStr(delta_str_dict.get('suspected_cls', '')), | 109 _EncodeStr(delta_str_dict.get('suspected_cls', '')), |
| 108 _EncodeStr(delta_str_dict.get('regression_range', '')) | 110 _EncodeStr(delta_str_dict.get('regression_range', '')) |
| 109 )) | 111 )) |
| OLD | NEW |