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 <[email protected]> git-svn-id: http://test.kernel.org/svn/autotest/trunk@1034 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/bin/autotest_utils.py b/client/bin/autotest_utils.py index d463a20..e171494 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 @@ 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)