| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS 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 """Common python commands used by various build scripts.""" | 5 """Common python commands used by various build scripts.""" |
| 6 | 6 |
| 7 import os |
| 7 import subprocess | 8 import subprocess |
| 8 import sys | 9 import sys |
| 9 | 10 |
| 10 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() | 11 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() |
| 11 | 12 |
| 12 def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, | 13 def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, |
| 13 exit_code=False, redirect_stdout=False, redirect_stderr=False, | 14 exit_code=False, redirect_stdout=False, redirect_stderr=False, |
| 14 cwd=None, input=None, enter_chroot=False): | 15 cwd=None, input=None, enter_chroot=False): |
| 15 """Runs a shell command. | 16 """Runs a shell command. |
| 16 | 17 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 119 |
| 119 | 120 |
| 120 def Info(message): | 121 def Info(message): |
| 121 """Emits a blue informational message and continues execution. | 122 """Emits a blue informational message and continues execution. |
| 122 | 123 |
| 123 Keyword arguments: | 124 Keyword arguments: |
| 124 message: The message to be emitted. | 125 message: The message to be emitted. |
| 125 """ | 126 """ |
| 126 print >> sys.stderr, ( | 127 print >> sys.stderr, ( |
| 127 Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message)) | 128 Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message)) |
| 129 |
| 130 |
| 131 def ListFiles(base_dir): |
| 132 """Recurively list files in a directory. |
| 133 |
| 134 Keyword arguments: |
| 135 base_dir: directory to start recursively listing in. |
| 136 |
| 137 Returns: |
| 138 A list of files relative to the base_dir path or |
| 139 An empty list of there are no files in the directories. |
| 140 """ |
| 141 directories = [base_dir] |
| 142 files_list = [] |
| 143 while directories: |
| 144 directory = directories.pop() |
| 145 for name in os.listdir(directory): |
| 146 fullpath = os.path.join(directory, name) |
| 147 if os.path.isfile(fullpath): |
| 148 files_list.append(fullpath) |
| 149 elif os.path.isdir(fullpath): |
| 150 directories.append(fullpath) |
| 151 |
| 152 return files_list |
| OLD | NEW |