Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chromite/lib/cros_build_lib.py

Issue 3325017: Add ListFiles a function to recursively list files in a directory. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils
Patch Set: Simplify while statement Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chromite/lib/cros_build_lib_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | chromite/lib/cros_build_lib_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698