blob: a20101d30ebc16f94c3abc18659cec8369f8d487 [file] [log] [blame]
Geoff Lang0e435462013-09-03 15:21:51 -04001import fnmatch
2import os
3import sys
4
Geoff Langd5da3292014-02-06 13:24:33 -05005dirs = [ ]
6types = [ ]
7excludes = [ ]
Geoff Lang0e435462013-09-03 15:21:51 -04008
Geoff Langd5da3292014-02-06 13:24:33 -05009# Default to accepting a list of directories first
10curArray = dirs
11
12# Iterate over the arguments and add them to the arrays
Geoff Lang0e435462013-09-03 15:21:51 -040013for i in range(1, len(sys.argv)):
14 arg = sys.argv[i]
Geoff Langd5da3292014-02-06 13:24:33 -050015
16 if arg == "-dirs":
17 curArray = dirs
Geoff Lang0e435462013-09-03 15:21:51 -040018 continue
Geoff Lang1106aeb2014-02-06 11:06:50 -050019
Geoff Langd5da3292014-02-06 13:24:33 -050020 if arg == "-types":
21 curArray = types
22 continue
Geoff Lang0e435462013-09-03 15:21:51 -040023
Geoff Langd5da3292014-02-06 13:24:33 -050024 if arg == "-excludes":
25 curArray = excludes
26 continue
27
28 curArray.append(arg)
29
30# If no directories were specified, use the current directory
31if len(dirs) == 0:
32 dirs.append(".")
33
34# If no types were specified, accept all types
35if len(types) == 0:
36 types.append("*")
37
38# Walk the directories listed and compare with type and exclude lists
39for rootdir in dirs:
Geoff Lang0e435462013-09-03 15:21:51 -040040 for root, dirnames, filenames in os.walk(rootdir):
41 for file in filenames:
Geoff Langd5da3292014-02-06 13:24:33 -050042 fullPath = os.path.join(root, file).replace("\\", "/")
43 for type in types:
44 if fnmatch.fnmatchcase(fullPath, type):
45 excluded = False
46 for exclude in excludes:
47 if fnmatch.fnmatchcase(fullPath, exclude):
48 excluded = True
49 break
50
51 if not excluded:
52 print fullPath
53 break