Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 1 | import fnmatch |
| 2 | import os |
| 3 | import sys |
| 4 | |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame^] | 5 | dirs = [ ] |
| 6 | types = [ ] |
| 7 | excludes = [ ] |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 8 | |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame^] | 9 | # Default to accepting a list of directories first |
| 10 | curArray = dirs |
| 11 | |
| 12 | # Iterate over the arguments and add them to the arrays |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 13 | for i in range(1, len(sys.argv)): |
| 14 | arg = sys.argv[i] |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame^] | 15 | |
| 16 | if arg == "-dirs": |
| 17 | curArray = dirs |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 18 | continue |
Geoff Lang | 1106aeb | 2014-02-06 11:06:50 -0500 | [diff] [blame] | 19 | |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame^] | 20 | if arg == "-types": |
| 21 | curArray = types |
| 22 | continue |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 23 | |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame^] | 24 | if arg == "-excludes": |
| 25 | curArray = excludes |
| 26 | continue |
| 27 | |
| 28 | curArray.append(arg) |
| 29 | |
| 30 | # If no directories were specified, use the current directory |
| 31 | if len(dirs) == 0: |
| 32 | dirs.append(".") |
| 33 | |
| 34 | # If no types were specified, accept all types |
| 35 | if len(types) == 0: |
| 36 | types.append("*") |
| 37 | |
| 38 | # Walk the directories listed and compare with type and exclude lists |
| 39 | for rootdir in dirs: |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 40 | for root, dirnames, filenames in os.walk(rootdir): |
| 41 | for file in filenames: |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame^] | 42 | 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 |