| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 | 5 |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 import tempfile | 13 import tempfile |
| 14 | 14 |
| 15 from proc_maps import ProcMaps | 15 from proc_maps import ProcMaps |
| 16 | 16 |
| 17 | 17 |
| 18 LOGGER = logging.getLogger('prepare_symbol_info') | 18 LOGGER = logging.getLogger('prepare_symbol_info') |
| 19 | 19 |
| 20 | 20 |
| 21 def _dump_command_result(command, output_dir_path, basename, suffix): | 21 def _dump_command_result(command, output_dir_path, basename, suffix): |
| 22 handle_out, filename_out = tempfile.mkstemp( | 22 handle_out, filename_out = tempfile.mkstemp( |
| 23 suffix=suffix, prefix=basename + '.', dir=output_dir_path) | 23 suffix=suffix, prefix=basename + '.', dir=output_dir_path) |
| 24 handle_err, filename_err = tempfile.mkstemp( | 24 handle_err, filename_err = tempfile.mkstemp( |
| 25 suffix=suffix + '.err', prefix=basename + '.', dir=output_dir_path) | 25 suffix=suffix + '.err', prefix=basename + '.', dir=output_dir_path) |
| 26 error = False | 26 error = False |
| 27 try: | 27 try: |
| 28 subprocess.check_call( | 28 subprocess.check_call( |
| 29 command, stdout=handle_out, stderr=handle_err, shell=True) | 29 command, stdout=handle_out, stderr=handle_err, shell=True) |
| 30 except: | 30 except (OSError, subprocess.CalledProcessError): |
| 31 error = True | 31 error = True |
| 32 finally: | 32 finally: |
| 33 os.close(handle_err) | 33 os.close(handle_err) |
| 34 os.close(handle_out) | 34 os.close(handle_out) |
| 35 | 35 |
| 36 if os.path.exists(filename_err): | 36 if os.path.exists(filename_err): |
| 37 if LOGGER.getEffectiveLevel() <= logging.DEBUG: | 37 if LOGGER.getEffectiveLevel() <= logging.DEBUG: |
| 38 with open(filename_err, 'r') as f: | 38 with open(filename_err, 'r') as f: |
| 39 for line in f: | 39 for line in f: |
| 40 LOGGER.debug(line.rstrip()) | 40 LOGGER.debug(line.rstrip()) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 output_dir_path = tempfile.mkdtemp() | 105 output_dir_path = tempfile.mkdtemp() |
| 106 used_tempdir = True | 106 used_tempdir = True |
| 107 LOGGER.warn('Using a temporary directory "%s".' % output_dir_path) | 107 LOGGER.warn('Using a temporary directory "%s".' % output_dir_path) |
| 108 else: | 108 else: |
| 109 LOGGER.warn('The directory "%s" is not available.' % output_dir_path) | 109 LOGGER.warn('The directory "%s" is not available.' % output_dir_path) |
| 110 return None, used_tempdir | 110 return None, used_tempdir |
| 111 else: | 111 else: |
| 112 LOGGER.info('Creating a new directory "%s".' % output_dir_path) | 112 LOGGER.info('Creating a new directory "%s".' % output_dir_path) |
| 113 try: | 113 try: |
| 114 os.mkdir(output_dir_path) | 114 os.mkdir(output_dir_path) |
| 115 except OSError, e: | 115 except OSError: |
| 116 LOGGER.warn('A directory "%s" cannot be created.' % output_dir_path) | 116 LOGGER.warn('A directory "%s" cannot be created.' % output_dir_path) |
| 117 if use_tempdir: | 117 if use_tempdir: |
| 118 output_dir_path = tempfile.mkdtemp() | 118 output_dir_path = tempfile.mkdtemp() |
| 119 used_tempdir = True | 119 used_tempdir = True |
| 120 LOGGER.warn('Using a temporary directory "%s".' % output_dir_path) | 120 LOGGER.warn('Using a temporary directory "%s".' % output_dir_path) |
| 121 else: | 121 else: |
| 122 LOGGER.warn('The directory "%s" is not available.' % output_dir_path) | 122 LOGGER.warn('The directory "%s" is not available.' % output_dir_path) |
| 123 return None, used_tempdir | 123 return None, used_tempdir |
| 124 | 124 |
| 125 shutil.copyfile(maps_path, os.path.join(output_dir_path, 'maps')) | 125 shutil.copyfile(maps_path, os.path.join(output_dir_path, 'maps')) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 elif len(sys.argv) == 2: | 178 elif len(sys.argv) == 2: |
| 179 result, _ = prepare_symbol_info(sys.argv[1]) | 179 result, _ = prepare_symbol_info(sys.argv[1]) |
| 180 else: | 180 else: |
| 181 result, _ = prepare_symbol_info(sys.argv[1], sys.argv[2]) | 181 result, _ = prepare_symbol_info(sys.argv[1], sys.argv[2]) |
| 182 | 182 |
| 183 return not result | 183 return not result |
| 184 | 184 |
| 185 | 185 |
| 186 if __name__ == '__main__': | 186 if __name__ == '__main__': |
| 187 sys.exit(main()) | 187 sys.exit(main()) |
| OLD | NEW |