diff options
author | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2007-12-04 22:50:14 +0000 |
---|---|---|
committer | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2007-12-04 22:50:14 +0000 |
commit | 9921ccaac7e25c0c3f908a03f410ee08fc969768 (patch) | |
tree | 81ddb53cb023238ba2cb4cc6bb67c046484fc206 /client/bin/autotest_utils.py | |
parent | 22a001a592561fcaf2bcea07bfad09de0f737ed8 (diff) |
Add locate() function to autotest_utils. Acts much like:
find . -name 'pattern' and returns a list of files matching
the pattern.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@1034 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'client/bin/autotest_utils.py')
-rwxr-xr-x | client/bin/autotest_utils.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/client/bin/autotest_utils.py b/client/bin/autotest_utils.py index d463a201..e1714948 100755 --- a/client/bin/autotest_utils.py +++ b/client/bin/autotest_utils.py @@ -3,7 +3,7 @@ import os,os.path,shutil,urllib,sys,signal,commands,pickle,glob,statvfs from common.error import * -import re,string +import re,string,fnmatch def grep(pattern, file): """ @@ -561,6 +561,14 @@ def write_keyval(path, dictionary): keyval.close() +# much like find . -name 'pattern' +def locate(pattern, root=os.getcwd()): + for path, dirs, files in os.walk(root): + for f in [os.path.abspath(os.path.join(path, f)) + for f in files if fnmatch.fnmatch(f, pattern)]: + yield f + + def freespace(path): # Find free space available in bytes s = os.statvfs(path) |