blob: 06ebf9d44407cab106e04ee9e63a723ce32d1bb0 [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 Lang373d7932014-02-24 10:08:16 -05008files = [ ]
Geoff Lang0e435462013-09-03 15:21:51 -04009
Geoff Langd5da3292014-02-06 13:24:33 -050010# Default to accepting a list of directories first
11curArray = dirs
12
13# Iterate over the arguments and add them to the arrays
Geoff Lang0e435462013-09-03 15:21:51 -040014for i in range(1, len(sys.argv)):
15 arg = sys.argv[i]
Geoff Langd5da3292014-02-06 13:24:33 -050016
17 if arg == "-dirs":
18 curArray = dirs
Geoff Lang0e435462013-09-03 15:21:51 -040019 continue
Geoff Lang1106aeb2014-02-06 11:06:50 -050020
Geoff Langd5da3292014-02-06 13:24:33 -050021 if arg == "-types":
22 curArray = types
23 continue
Geoff Lang0e435462013-09-03 15:21:51 -040024
Geoff Langd5da3292014-02-06 13:24:33 -050025 if arg == "-excludes":
26 curArray = excludes
27 continue
28
29 curArray.append(arg)
30
31# If no directories were specified, use the current directory
32if len(dirs) == 0:
33 dirs.append(".")
34
35# If no types were specified, accept all types
36if len(types) == 0:
37 types.append("*")
38
39# Walk the directories listed and compare with type and exclude lists
40for rootdir in dirs:
Geoff Lang0e435462013-09-03 15:21:51 -040041 for root, dirnames, filenames in os.walk(rootdir):
42 for file in filenames:
Geoff Lang9c90d7e2014-02-27 13:20:38 -050043 # Skip files that are "hidden"
44 if file.startswith("."):
45 continue;
46
Geoff Langd5da3292014-02-06 13:24:33 -050047 fullPath = os.path.join(root, file).replace("\\", "/")
48 for type in types:
49 if fnmatch.fnmatchcase(fullPath, type):
50 excluded = False
51 for exclude in excludes:
52 if fnmatch.fnmatchcase(fullPath, exclude):
53 excluded = True
54 break
55
56 if not excluded:
Geoff Lang373d7932014-02-24 10:08:16 -050057 files.append(fullPath)
Geoff Langd5da3292014-02-06 13:24:33 -050058 break
Geoff Lang373d7932014-02-24 10:08:16 -050059
60files.sort()
61for file in files:
62 print file