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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chromite/lib/cros_build_lib_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromite/lib/cros_build_lib.py
diff --git a/chromite/lib/cros_build_lib.py b/chromite/lib/cros_build_lib.py
index a0cd73c6edaac26c2324c7af158a5c00d7bf762d..825e43cc398555736340fe6ec7433ecc903f1ae1 100644
--- a/chromite/lib/cros_build_lib.py
+++ b/chromite/lib/cros_build_lib.py
@@ -4,6 +4,7 @@
"""Common python commands used by various build scripts."""
+import os
import subprocess
import sys
@@ -125,3 +126,27 @@ def Info(message):
"""
print >> sys.stderr, (
Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message))
+
+
+def ListFiles(base_dir):
+ """Recurively list files in a directory.
+
+ Keyword arguments:
+ base_dir: directory to start recursively listing in.
+
+ Returns:
+ A list of files relative to the base_dir path or
+ An empty list of there are no files in the directories.
+ """
+ directories = [base_dir]
+ files_list = []
+ while directories:
+ directory = directories.pop()
+ for name in os.listdir(directory):
+ fullpath = os.path.join(directory, name)
+ if os.path.isfile(fullpath):
+ files_list.append(fullpath)
+ elif os.path.isdir(fullpath):
+ directories.append(fullpath)
+
+ return files_list
« 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