Christopher Dunn | dc0f736 | 2011-06-21 21:18:49 +0000 | [diff] [blame] | 1 | import fnmatch |
| 2 | import os |
| 3 | |
| 4 | def generate( env ): |
| 5 | def Glob( env, includes = None, excludes = None, dir = '.' ): |
| 6 | """Adds Glob( includes = Split( '*' ), excludes = None, dir = '.') |
| 7 | helper function to environment. |
| 8 | |
| 9 | Glob both the file-system files. |
| 10 | |
| 11 | includes: list of file name pattern included in the return list when matched. |
| 12 | excludes: list of file name pattern exluced from the return list. |
| 13 | |
| 14 | Example: |
| 15 | sources = env.Glob( ("*.cpp", '*.h'), "~*.cpp", "#src" ) |
| 16 | """ |
| 17 | def filterFilename(path): |
| 18 | abs_path = os.path.join( dir, path ) |
| 19 | if not os.path.isfile(abs_path): |
| 20 | return 0 |
| 21 | fn = os.path.basename(path) |
| 22 | match = 0 |
| 23 | for include in includes: |
| 24 | if fnmatch.fnmatchcase( fn, include ): |
| 25 | match = 1 |
| 26 | break |
| 27 | if match == 1 and not excludes is None: |
| 28 | for exclude in excludes: |
| 29 | if fnmatch.fnmatchcase( fn, exclude ): |
| 30 | match = 0 |
| 31 | break |
| 32 | return match |
| 33 | if includes is None: |
| 34 | includes = ('*',) |
| 35 | elif type(includes) in ( type(''), type(u'') ): |
| 36 | includes = (includes,) |
| 37 | if type(excludes) in ( type(''), type(u'') ): |
| 38 | excludes = (excludes,) |
| 39 | dir = env.Dir(dir).abspath |
| 40 | paths = os.listdir( dir ) |
| 41 | def makeAbsFileNode( path ): |
| 42 | return env.File( os.path.join( dir, path ) ) |
| 43 | nodes = filter( filterFilename, paths ) |
| 44 | return map( makeAbsFileNode, nodes ) |
| 45 | |
| 46 | from SCons.Script import Environment |
Baptiste Lepilleur | f66d370 | 2008-01-20 16:49:53 +0000 | [diff] [blame] | 47 | Environment.Glob = Glob |
Christopher Dunn | dc0f736 | 2011-06-21 21:18:49 +0000 | [diff] [blame] | 48 | |
| 49 | def exists(env): |
| 50 | """ |
| 51 | Tool always exists. |
| 52 | """ |
| 53 | return True |