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 | 373d793 | 2014-02-24 10:08:16 -0500 | [diff] [blame] | 8 | files = [ ] |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 9 | |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame] | 10 | # Default to accepting a list of directories first |
| 11 | curArray = dirs |
| 12 | |
| 13 | # Iterate over the arguments and add them to the arrays |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 14 | for i in range(1, len(sys.argv)): |
| 15 | arg = sys.argv[i] |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame] | 16 | |
| 17 | if arg == "-dirs": |
| 18 | curArray = dirs |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 19 | continue |
Geoff Lang | 1106aeb | 2014-02-06 11:06:50 -0500 | [diff] [blame] | 20 | |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame] | 21 | if arg == "-types": |
| 22 | curArray = types |
| 23 | continue |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 24 | |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame] | 25 | if arg == "-excludes": |
| 26 | curArray = excludes |
| 27 | continue |
| 28 | |
| 29 | curArray.append(arg) |
| 30 | |
| 31 | # If no directories were specified, use the current directory |
| 32 | if len(dirs) == 0: |
| 33 | dirs.append(".") |
| 34 | |
| 35 | # If no types were specified, accept all types |
| 36 | if len(types) == 0: |
| 37 | types.append("*") |
| 38 | |
| 39 | # Walk the directories listed and compare with type and exclude lists |
| 40 | for rootdir in dirs: |
Geoff Lang | 0e43546 | 2013-09-03 15:21:51 -0400 | [diff] [blame] | 41 | for root, dirnames, filenames in os.walk(rootdir): |
| 42 | for file in filenames: |
Geoff Lang | 9c90d7e | 2014-02-27 13:20:38 -0500 | [diff] [blame] | 43 | # Skip files that are "hidden" |
| 44 | if file.startswith("."): |
| 45 | continue; |
| 46 | |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame] | 47 | 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 Lang | 373d793 | 2014-02-24 10:08:16 -0500 | [diff] [blame] | 57 | files.append(fullPath) |
Geoff Lang | d5da329 | 2014-02-06 13:24:33 -0500 | [diff] [blame] | 58 | break |
Geoff Lang | 373d793 | 2014-02-24 10:08:16 -0500 | [diff] [blame] | 59 | |
| 60 | files.sort() |
| 61 | for file in files: |
| 62 | print file |