| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 env = get_english_env(kwargs.get('env')) | 152 env = get_english_env(kwargs.get('env')) |
| 153 if env: | 153 if env: |
| 154 kwargs['env'] = env | 154 kwargs['env'] = env |
| 155 if kwargs.get('shell') is None: | 155 if kwargs.get('shell') is None: |
| 156 # *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 |
| 157 # executable, but shell=True makes subprocess on Linux fail when it's called | 157 # executable, but shell=True makes subprocess on Linux fail when it's called |
| 158 # with a list because it only tries to execute the first item in the list. | 158 # with a list because it only tries to execute the first item in the list. |
| 159 kwargs['shell'] = bool(sys.platform=='win32') | 159 kwargs['shell'] = bool(sys.platform=='win32') |
| 160 | 160 |
| 161 tmp_str = ' '.join(args) | 161 if isinstance(args, basestring): |
| 162 tmp_str = args |
| 163 elif isinstance(args, (list, tuple)): |
| 164 tmp_str = ' '.join(args) |
| 165 else: |
| 166 raise CalledProcessError(None, args, kwargs.get('cwd'), None, None) |
| 162 if kwargs.get('cwd', None): | 167 if kwargs.get('cwd', None): |
| 163 tmp_str += '; cwd=%s' % kwargs['cwd'] | 168 tmp_str += '; cwd=%s' % kwargs['cwd'] |
| 164 logging.debug(tmp_str) | 169 logging.debug(tmp_str) |
| 165 | 170 |
| 166 def fix(stream): | 171 def fix(stream): |
| 167 if kwargs.get(stream) in (VOID, os.devnull): | 172 if kwargs.get(stream) in (VOID, os.devnull): |
| 168 # Replaces VOID with handle to /dev/null. | 173 # Replaces VOID with handle to /dev/null. |
| 169 # Create a temporary file to workaround python's deadlock. | 174 # Create a temporary file to workaround python's deadlock. |
| 170 # http://docs.python.org/library/subprocess.html#subprocess.Popen.wait | 175 # http://docs.python.org/library/subprocess.html#subprocess.Popen.wait |
| 171 # When the pipe fills up, it will deadlock this process. Using a real file | 176 # When the pipe fills up, it will deadlock this process. Using a real file |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 301 |
| 297 Captures stdout of a process call and returns stdout only. | 302 Captures stdout of a process call and returns stdout only. |
| 298 | 303 |
| 299 - Throws if return code is not 0. | 304 - Throws if return code is not 0. |
| 300 - Works even prior to python 2.7. | 305 - Works even prior to python 2.7. |
| 301 - Blocks stdin by default if not specified since no output will be visible. | 306 - Blocks stdin by default if not specified since no output will be visible. |
| 302 - As per doc, "The stdout argument is not allowed as it is used internally." | 307 - As per doc, "The stdout argument is not allowed as it is used internally." |
| 303 """ | 308 """ |
| 304 kwargs.setdefault('stdin', VOID) | 309 kwargs.setdefault('stdin', VOID) |
| 305 return check_call_out(args, stdout=PIPE, **kwargs)[0] | 310 return check_call_out(args, stdout=PIPE, **kwargs)[0] |
| OLD | NEW |