aboutsummaryrefslogtreecommitdiff
path: root/testcase
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2016-05-30 16:11:14 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2016-05-30 16:11:14 +0900
commitc15a82489decf50137c0e25626b80d2fa8de17a8 (patch)
treed4bf779fd199933a8462f4b8d7365740662bba25 /testcase
parentaf134686a5bff1cfef2ac114795d5ec2c0886cd0 (diff)
Update findleaves.py and add a few testcases
Diffstat (limited to 'testcase')
-rw-r--r--testcase/find_command.mk2
-rwxr-xr-xtestcase/tools/findleaves.py36
2 files changed, 28 insertions, 10 deletions
diff --git a/testcase/find_command.mk b/testcase/find_command.mk
index a0bbc82..c3e8a07 100644
--- a/testcase/find_command.mk
+++ b/testcase/find_command.mk
@@ -116,6 +116,8 @@ endif
$(call run_find, build/tools/findleaves.py --mindepth=2 testdir file1)
$(call run_find, build/tools/findleaves.py --mindepth=3 testdir file1)
$(call run_find, build/tools/findleaves.py --mindepth=2 testdir file1)
+ $(call run_find, build/tools/findleaves.py --prune=dir1 --dir=testdir file1)
+ $(call run_find, build/tools/findleaves.py --prune=dir1 --dir=testdir file3 link3)
@echo missing chdir / testdir
$(call run_find, cd xxx && find .)
$(call run_find, if [ -d xxx ]; then find .; fi)
diff --git a/testcase/tools/findleaves.py b/testcase/tools/findleaves.py
index 3a9e508..72cc024 100755
--- a/testcase/tools/findleaves.py
+++ b/testcase/tools/findleaves.py
@@ -23,7 +23,7 @@
import os
import sys
-def perform_find(mindepth, prune, dirlist, filename):
+def perform_find(mindepth, prune, dirlist, filenames):
result = []
pruneleaves = set(map(lambda x: os.path.split(x)[1], prune))
for rootdir in dirlist:
@@ -48,19 +48,24 @@ def perform_find(mindepth, prune, dirlist, filename):
if depth < mindepth:
continue
# match
- if filename in files:
- result.append(os.path.join(root, filename))
- del dirs[:]
+ for filename in filenames:
+ if filename in files:
+ result.append(os.path.join(root, filename))
+ del dirs[:]
return result
def usage():
- sys.stderr.write("""Usage: %(progName)s [<options>] <dirlist> <filename>
+ sys.stderr.write("""Usage: %(progName)s [<options>] [--dir=<dir>] <filenames>
Options:
--mindepth=<mindepth>
Both behave in the same way as their find(1) equivalents.
--prune=<dirname>
Avoids returning results from inside any directory called <dirname>
(e.g., "*/out/*"). May be used multiple times.
+ --dir=<dir>
+ Add a directory to search. May be repeated multiple times. For backwards
+ compatibility, if no --dir argument is provided then all but the last entry
+ in <filenames> are treated as directories.
""" % {
"progName": os.path.split(sys.argv[0])[1],
})
@@ -69,6 +74,7 @@ Options:
def main(argv):
mindepth = -1
prune = []
+ dirlist = []
i=1
while i<len(argv) and len(argv[i])>2 and argv[i][0:2] == "--":
arg = argv[i]
@@ -82,14 +88,24 @@ def main(argv):
if len(p) == 0:
usage()
prune.append(p)
+ elif arg.startswith("--dir="):
+ d = arg[len("--dir="):]
+ if len(p) == 0:
+ usage()
+ dirlist.append(d)
else:
usage()
i += 1
- if len(argv)-i < 2: # need both <dirlist> and <filename>
- usage()
- dirlist = argv[i:-1]
- filename = argv[-1]
- results = list(set(perform_find(mindepth, prune, dirlist, filename)))
+ if len(dirlist) == 0: # backwards compatibility
+ if len(argv)-i < 2: # need both <dirlist> and <filename>
+ usage()
+ dirlist = argv[i:-1]
+ filenames = [argv[-1]]
+ else:
+ if len(argv)-i < 1: # need <filename>
+ usage()
+ filenames = argv[i:]
+ results = list(set(perform_find(mindepth, prune, dirlist, filenames)))
results.sort()
for r in results:
print r