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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return '\n'.join(filter(None, (out, self.stdout, self.stderr))) | 44 return '\n'.join(filter(None, (out, self.stdout, self.stderr))) |
45 | 45 |
46 | 46 |
47 ## Utility functions | 47 ## Utility functions |
48 | 48 |
49 | 49 |
50 def kill_pid(pid): | 50 def kill_pid(pid): |
51 """Kills a process by its process id.""" | 51 """Kills a process by its process id.""" |
52 try: | 52 try: |
53 # Unable to import 'module' | 53 # Unable to import 'module' |
54 # pylint: disable=F0401 | 54 # pylint: disable=E1101,F0401 |
55 import signal | 55 import signal |
56 return os.kill(pid, signal.SIGKILL) | 56 return os.kill(pid, signal.SIGKILL) |
57 except ImportError: | 57 except ImportError: |
58 pass | 58 pass |
59 | 59 |
60 | 60 |
61 def kill_win(process): | 61 def kill_win(process): |
62 """Kills a process with its windows handle. | 62 """Kills a process with its windows handle. |
63 | 63 |
64 Has no effect on other platforms. | 64 Has no effect on other platforms. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 SUBPROCESS_CLEANUP_HACKED = True | 98 SUBPROCESS_CLEANUP_HACKED = True |
99 | 99 |
100 | 100 |
101 def get_english_env(env): | 101 def get_english_env(env): |
102 """Forces LANG and/or LANGUAGE to be English. | 102 """Forces LANG and/or LANGUAGE to be English. |
103 | 103 |
104 Forces encoding to utf-8 for subprocesses. | 104 Forces encoding to utf-8 for subprocesses. |
105 | 105 |
106 Returns None if it is unnecessary. | 106 Returns None if it is unnecessary. |
107 """ | 107 """ |
| 108 if sys.platform == 'win32': |
| 109 return None |
108 env = env or os.environ | 110 env = env or os.environ |
109 | 111 |
110 # Test if it is necessary at all. | 112 # Test if it is necessary at all. |
111 is_english = lambda name: env.get(name, 'en').startswith('en') | 113 is_english = lambda name: env.get(name, 'en').startswith('en') |
112 | 114 |
113 if is_english('LANG') and is_english('LANGUAGE'): | 115 if is_english('LANG') and is_english('LANGUAGE'): |
114 return None | 116 return None |
115 | 117 |
116 # Requires modifications. | 118 # Requires modifications. |
117 env = env.copy() | 119 env = env.copy() |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 248 |
247 - Discards stderr. By default sets stderr=STDOUT. | 249 - Discards stderr. By default sets stderr=STDOUT. |
248 - Throws if return code is not 0. | 250 - Throws if return code is not 0. |
249 - Works even prior to python 2.7. | 251 - Works even prior to python 2.7. |
250 """ | 252 """ |
251 if kwargs.get('stdout') is None: | 253 if kwargs.get('stdout') is None: |
252 kwargs['stdout'] = PIPE | 254 kwargs['stdout'] = PIPE |
253 if kwargs.get('stderr') is None: | 255 if kwargs.get('stderr') is None: |
254 kwargs['stderr'] = STDOUT | 256 kwargs['stderr'] = STDOUT |
255 return check_call(args, **kwargs)[0] | 257 return check_call(args, **kwargs)[0] |
OLD | NEW |