| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import fnmatch | 5 import fnmatch |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import pipes | 8 import pipes |
| 9 import shlex | 9 import shlex |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 CHROMIUM_SRC = os.path.join(os.path.dirname(__file__), |
| 15 os.pardir, os.pardir, os.pardir, os.pardir) |
| 16 COLORAMA_ROOT = os.path.join(CHROMIUM_SRC, |
| 17 'third_party', 'colorama', 'src') |
| 18 |
| 14 | 19 |
| 15 def MakeDirectory(dir_path): | 20 def MakeDirectory(dir_path): |
| 16 try: | 21 try: |
| 17 os.makedirs(dir_path) | 22 os.makedirs(dir_path) |
| 18 except OSError: | 23 except OSError: |
| 19 pass | 24 pass |
| 20 | 25 |
| 21 | 26 |
| 22 def DeleteDirectory(dir_path): | 27 def DeleteDirectory(dir_path): |
| 23 if os.path.exists(dir_path): | 28 if os.path.exists(dir_path): |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 # A user should be able to simply copy and paste the command that failed | 98 # A user should be able to simply copy and paste the command that failed |
| 94 # into their shell. | 99 # into their shell. |
| 95 copyable_command = '( cd {}; {} )'.format(os.path.abspath(self.cwd), | 100 copyable_command = '( cd {}; {} )'.format(os.path.abspath(self.cwd), |
| 96 ' '.join(map(pipes.quote, self.args))) | 101 ' '.join(map(pipes.quote, self.args))) |
| 97 return 'Command failed: {}\n{}'.format(copyable_command, self.output) | 102 return 'Command failed: {}\n{}'.format(copyable_command, self.output) |
| 98 | 103 |
| 99 | 104 |
| 100 # This can be used in most cases like subprocess.check_output(). The output, | 105 # This can be used in most cases like subprocess.check_output(). The output, |
| 101 # particularly when the command fails, better highlights the command's failure. | 106 # particularly when the command fails, better highlights the command's failure. |
| 102 # If the command fails, raises a build_utils.CalledProcessError. | 107 # If the command fails, raises a build_utils.CalledProcessError. |
| 103 def CheckOutput(args, cwd=None, print_stdout=False, print_stderr=True, | 108 def CheckOutput(args, cwd=None, |
| 109 print_stdout=False, print_stderr=True, |
| 110 stdout_filter=None, |
| 111 stderr_filter=None, |
| 104 fail_func=lambda returncode, stderr: returncode != 0): | 112 fail_func=lambda returncode, stderr: returncode != 0): |
| 105 if not cwd: | 113 if not cwd: |
| 106 cwd = os.getcwd() | 114 cwd = os.getcwd() |
| 107 | 115 |
| 108 child = subprocess.Popen(args, | 116 child = subprocess.Popen(args, |
| 109 stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) | 117 stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) |
| 110 stdout, stderr = child.communicate() | 118 stdout, stderr = child.communicate() |
| 111 | 119 |
| 120 if stdout_filter is not None: |
| 121 stdout = stdout_filter(stdout) |
| 122 |
| 123 if stderr_filter is not None: |
| 124 stderr = stderr_filter(stderr) |
| 125 |
| 112 if fail_func(child.returncode, stderr): | 126 if fail_func(child.returncode, stderr): |
| 113 raise CalledProcessError(cwd, args, stdout + stderr) | 127 raise CalledProcessError(cwd, args, stdout + stderr) |
| 114 | 128 |
| 115 if print_stdout: | 129 if print_stdout: |
| 116 sys.stdout.write(stdout) | 130 sys.stdout.write(stdout) |
| 117 if print_stderr: | 131 if print_stderr: |
| 118 sys.stderr.write(stderr) | 132 sys.stderr.write(stderr) |
| 119 | 133 |
| 120 return stdout | 134 return stdout |
| 121 | 135 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 143 | 157 |
| 144 | 158 |
| 145 def PrintWarning(message): | 159 def PrintWarning(message): |
| 146 print 'WARNING: ' + message | 160 print 'WARNING: ' + message |
| 147 | 161 |
| 148 | 162 |
| 149 def PrintBigWarning(message): | 163 def PrintBigWarning(message): |
| 150 print '***** ' * 8 | 164 print '***** ' * 8 |
| 151 PrintWarning(message) | 165 PrintWarning(message) |
| 152 print '***** ' * 8 | 166 print '***** ' * 8 |
| OLD | NEW |