| OLD | NEW |
| 1 # coding=utf8 | 1 # coding=utf8 |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 """Collection of subprocess wrapper functions. | 5 """Collection of subprocess wrapper functions. |
| 6 | 6 |
| 7 In theory you shouldn't need anything else in subprocess, or this module failed. | 7 In theory you shouldn't need anything else in subprocess, or this module failed. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 from __future__ import with_statement | 10 from __future__ import with_statement |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 env = env.copy() | 125 env = env.copy() |
| 126 def fix_lang(name): | 126 def fix_lang(name): |
| 127 if not is_english(name): | 127 if not is_english(name): |
| 128 env[name] = 'en_US.UTF-8' | 128 env[name] = 'en_US.UTF-8' |
| 129 fix_lang('LANG') | 129 fix_lang('LANG') |
| 130 fix_lang('LANGUAGE') | 130 fix_lang('LANGUAGE') |
| 131 return env | 131 return env |
| 132 | 132 |
| 133 | 133 |
| 134 def Popen(args, **kwargs): | 134 def Popen(args, **kwargs): |
| 135 """Wraps subprocess.Popen(). | 135 """Wraps subprocess.Popen() with various workarounds. |
| 136 | 136 |
| 137 Returns a subprocess.Popen object. | 137 Returns a subprocess.Popen object. |
| 138 | 138 |
| 139 - Forces English output since it's easier to parse the stdout if it is always | 139 - Forces English output since it's easier to parse the stdout if it is always |
| 140 in English. | 140 in English. |
| 141 - Sets shell=True on windows by default. You can override this by forcing | 141 - Sets shell=True on windows by default. You can override this by forcing |
| 142 shell parameter to a value. | 142 shell parameter to a value. |
| 143 - Adds support for VOID to not buffer when not needed. | 143 - Adds support for VOID to not buffer when not needed. |
| 144 | 144 |
| 145 Note: Popen() can throw OSError when cwd or args[0] doesn't exist. | 145 Note: Popen() can throw OSError when cwd or args[0] doesn't exist. Translate |
| 146 exceptions generated by cygwin when it fails trying to emulate fork(). |
| 146 """ | 147 """ |
| 147 # Make sure we hack subprocess if necessary. | 148 # Make sure we hack subprocess if necessary. |
| 148 hack_subprocess() | 149 hack_subprocess() |
| 149 add_kill() | 150 add_kill() |
| 150 | 151 |
| 151 env = get_english_env(kwargs.get('env')) | 152 env = get_english_env(kwargs.get('env')) |
| 152 if env: | 153 if env: |
| 153 kwargs['env'] = env | 154 kwargs['env'] = env |
| 154 if kwargs.get('shell') is None: | 155 if kwargs.get('shell') is None: |
| 155 # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for the | 156 # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for the |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 - Works even prior to python 2.7. | 303 - Works even prior to python 2.7. |
| 303 - Blocks stdin by default since no output will be visible. | 304 - Blocks stdin by default since no output will be visible. |
| 304 """ | 305 """ |
| 305 if kwargs.get('stdin') is None: | 306 if kwargs.get('stdin') is None: |
| 306 kwargs['stdin'] = VOID | 307 kwargs['stdin'] = VOID |
| 307 if kwargs.get('stdout') is None: | 308 if kwargs.get('stdout') is None: |
| 308 kwargs['stdout'] = PIPE | 309 kwargs['stdout'] = PIPE |
| 309 if kwargs.get('stderr') is None: | 310 if kwargs.get('stderr') is None: |
| 310 kwargs['stderr'] = STDOUT | 311 kwargs['stderr'] = STDOUT |
| 311 return check_call_out(args, **kwargs)[0] | 312 return check_call_out(args, **kwargs)[0] |
| OLD | NEW |