feb19babff01431759e45a43e981a9e8e2f196a6
[senf.git] / senfscons / nodeglob.py
1 import fnmatch
2 import os
3
4 def glob(match):
5     """Similar to glob.glob, except globs SCons nodes, and thus sees
6     generated files and files from build directories.  Basically, it sees
7     anything SCons knows about.  A key subtlety is that since this function
8     operates on generated nodes as well as source nodes on the filesystem,
9     it needs to be called after builders that generate files you want to
10     include."""
11     def fn_filter(node):
12         fn = str(node)
13         return fnmatch.fnmatch(os.path.basename(fn), match)
14
15     here = Dir('.')
16
17     children = here.all_children()
18     nodes = map(File, filter(fn_filter, children))
19     node_srcs = [n.srcnode() for n in nodes]
20
21     src = here.srcnode()
22     if src is not here:
23         src_children = map(File, filter(fn_filter, src.all_children()))
24         for s in src_children:
25             if s not in node_srcs:
26                 nodes.append(File(os.path.basename(str(s))))
27
28     return nodes