| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2012 The LUCI Authors. All rights reserved. | 2 # Copyright 2012 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Runs a command with optional isolated input/output. | 6 """Runs a command with optional isolated input/output. |
| 7 | 7 |
| 8 Despite name "run_isolated", can run a generic non-isolated command specified as | 8 Despite name "run_isolated", can run a generic non-isolated command specified as |
| 9 args. | 9 args. |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 import auth | 51 import auth |
| 52 import cipd | 52 import cipd |
| 53 import isolateserver | 53 import isolateserver |
| 54 | 54 |
| 55 | 55 |
| 56 ISOLATED_OUTDIR_PARAMETER = '${ISOLATED_OUTDIR}' | 56 ISOLATED_OUTDIR_PARAMETER = '${ISOLATED_OUTDIR}' |
| 57 EXECUTABLE_SUFFIX_PARAMETER = '${EXECUTABLE_SUFFIX}' | 57 EXECUTABLE_SUFFIX_PARAMETER = '${EXECUTABLE_SUFFIX}' |
| 58 SWARMING_BOT_FILE_PARAMETER = '${SWARMING_BOT_FILE}' | 58 SWARMING_BOT_FILE_PARAMETER = '${SWARMING_BOT_FILE}' |
| 59 | 59 |
| 60 # Absolute path to this file (can be None if running from zip on Mac). | 60 # Absolute path to this file (can be None if running from zip on Mac). |
| 61 THIS_FILE_PATH = os.path.abspath(__file__) if __file__ else None | 61 THIS_FILE_PATH = os.path.abspath( |
| 62 __file__.decode(sys.getfilesystemencoding())) if __file__ else None |
| 62 | 63 |
| 63 # Directory that contains this file (might be inside zip package). | 64 # Directory that contains this file (might be inside zip package). |
| 64 BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__ else None | 65 BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__.decode( |
| 66 sys.getfilesystemencoding()) else None |
| 65 | 67 |
| 66 # Directory that contains currently running script file. | 68 # Directory that contains currently running script file. |
| 67 if zip_package.get_main_script_path(): | 69 if zip_package.get_main_script_path(): |
| 68 MAIN_DIR = os.path.dirname( | 70 MAIN_DIR = os.path.dirname( |
| 69 os.path.abspath(zip_package.get_main_script_path())) | 71 os.path.abspath(zip_package.get_main_script_path())) |
| 70 else: | 72 else: |
| 71 # This happens when 'import run_isolated' is executed at the python | 73 # This happens when 'import run_isolated' is executed at the python |
| 72 # interactive prompt, in that case __file__ is undefined. | 74 # interactive prompt, in that case __file__ is undefined. |
| 73 MAIN_DIR = None | 75 MAIN_DIR = None |
| 74 | 76 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 def run_command(command, cwd, tmp_dir, hard_timeout, grace_period): | 188 def run_command(command, cwd, tmp_dir, hard_timeout, grace_period): |
| 187 """Runs the command. | 189 """Runs the command. |
| 188 | 190 |
| 189 Returns: | 191 Returns: |
| 190 tuple(process exit code, bool if had a hard timeout) | 192 tuple(process exit code, bool if had a hard timeout) |
| 191 """ | 193 """ |
| 192 logging.info('run_command(%s, %s)' % (command, cwd)) | 194 logging.info('run_command(%s, %s)' % (command, cwd)) |
| 193 | 195 |
| 194 env = os.environ.copy() | 196 env = os.environ.copy() |
| 195 if sys.platform == 'darwin': | 197 if sys.platform == 'darwin': |
| 196 env['TMPDIR'] = tmp_dir.encode('ascii') | 198 env['TMPDIR'] = tmp_dir.encode(sys.getfilesystemencoding()) |
| 197 elif sys.platform == 'win32': | 199 elif sys.platform == 'win32': |
| 198 env['TEMP'] = tmp_dir.encode('ascii') | 200 env['TEMP'] = tmp_dir.encode(sys.getfilesystemencoding()) |
| 199 else: | 201 else: |
| 200 env['TMP'] = tmp_dir.encode('ascii') | 202 env['TMP'] = tmp_dir.encode(sys.getfilesystemencoding()) |
| 201 exit_code = None | 203 exit_code = None |
| 202 had_hard_timeout = False | 204 had_hard_timeout = False |
| 203 with tools.Profiler('RunTest'): | 205 with tools.Profiler('RunTest'): |
| 204 proc = None | 206 proc = None |
| 205 had_signal = [] | 207 had_signal = [] |
| 206 try: | 208 try: |
| 207 # TODO(maruel): This code is imperfect. It doesn't handle well signals | 209 # TODO(maruel): This code is imperfect. It doesn't handle well signals |
| 208 # during the download phase and there's short windows were things can go | 210 # during the download phase and there's short windows were things can go |
| 209 # wrong. | 211 # wrong. |
| 210 def handler(signum, _frame): | 212 def handler(signum, _frame): |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 except cipd.Error as ex: | 747 except cipd.Error as ex: |
| 746 print >> sys.stderr, ex.message | 748 print >> sys.stderr, ex.message |
| 747 return 1 | 749 return 1 |
| 748 | 750 |
| 749 | 751 |
| 750 if __name__ == '__main__': | 752 if __name__ == '__main__': |
| 751 subprocess42.inhibit_os_error_reporting() | 753 subprocess42.inhibit_os_error_reporting() |
| 752 # Ensure that we are always running with the correct encoding. | 754 # Ensure that we are always running with the correct encoding. |
| 753 fix_encoding.fix_encoding() | 755 fix_encoding.fix_encoding() |
| 754 sys.exit(main(sys.argv[1:])) | 756 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |