OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """A wrapper for subprocess to make calling shell commands easier.""" | 5 """A wrapper for subprocess to make calling shell commands easier.""" |
6 | 6 |
7 | 7 import os |
8 import logging | 8 import logging |
9 import subprocess | 9 import subprocess |
10 | 10 |
| 11 import constants |
11 | 12 |
12 def RunCmd(args, cwd=None): | 13 def RunCmd(args, cwd=None): |
13 """Opens a subprocess to execute a program and returns its return value. | 14 """Opens a subprocess to execute a program and returns its return value. |
14 | 15 |
15 Args: | 16 Args: |
16 args: A string or a sequence of program arguments. The program to execute is | 17 args: A string or a sequence of program arguments. The program to execute is |
17 the string or the first item in the args sequence. | 18 the string or the first item in the args sequence. |
18 cwd: If not None, the subprocess's current directory will be changed to | 19 cwd: If not None, the subprocess's current directory will be changed to |
19 |cwd| before it's executed. | 20 |cwd| before it's executed. |
20 | 21 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 """ | 59 """ |
59 logging.info(str(args) + ' ' + (cwd or '')) | 60 logging.info(str(args) + ' ' + (cwd or '')) |
60 p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE, | 61 p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE, |
61 stderr=subprocess.PIPE, shell=shell) | 62 stderr=subprocess.PIPE, shell=shell) |
62 stdout, stderr = p.communicate() | 63 stdout, stderr = p.communicate() |
63 exit_code = p.returncode | 64 exit_code = p.returncode |
64 if stderr: | 65 if stderr: |
65 logging.critical(stderr) | 66 logging.critical(stderr) |
66 logging.info(stdout[:4096]) # Truncate output longer than 4k. | 67 logging.info(stdout[:4096]) # Truncate output longer than 4k. |
67 return (exit_code, stdout) | 68 return (exit_code, stdout) |
| 69 |
| 70 class OutDirectory(object): |
| 71 _out_directory = constants.CHROME_DIR |
| 72 @staticmethod |
| 73 def set(out_directory): |
| 74 OutDirectory._out_directory = out_directory |
| 75 @staticmethod |
| 76 def get(): |
| 77 return OutDirectory._out_directory |
OLD | NEW |