Add children() methods for nodes.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 2 Oct 2001 13:11:42 +0000 (13:11 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 2 Oct 2001 13:11:42 +0000 (13:11 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@81 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py
src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py

index 259576619c5aeb101f7244a559e7bd7cd1f5dc6d..2950c9788adfcb1ce6cab97698a2b34b1a21a3fa 100644 (file)
@@ -226,6 +226,11 @@ class Dir(Node):
         else:
             return self.entries['..'].root()
 
+    def children(self):
+       return map(lambda x, s=self: s.entries[x],
+                  filter(lambda k: k != '.' and k != '..',
+                         self.entries.keys()))
+
 
 # XXX TODO?
 # rfile
index 1cffd8c8d2f0c6e2d07ab33fd3152f73de5799e4..568022bd5596d77892286264c67b5a9a1ac8cb38 100644 (file)
@@ -95,6 +95,18 @@ class FSTestCase(unittest.TestCase):
         except:
             raise
 
+       # Test Dir.children()
+       dir = fs.Dir('ddd')
+       fs.File('ddd/f1')
+       fs.File('ddd/f2')
+       fs.File('ddd/f3')
+       fs.Dir('ddd/d1')
+       fs.Dir('ddd/d1/f4')
+       fs.Dir('ddd/d1/f5')
+       kids = map(lambda x: x.path, dir.children())
+       kids.sort()
+       assert kids == ['ddd/d1/', 'ddd/f1', 'ddd/f2', 'ddd/f3']
+
         # Test for sub-classing of node building.
         global built_it
 
index 26cf6bdaaeaac17f8ddec79386f5a3d0e22af05c..3ea6d7f4811b7420cd22f980022f95c35e8e723e 100644 (file)
@@ -119,6 +119,17 @@ class NodeTestCase(unittest.TestCase):
        node.add_source(['two', 'three'])
        assert node.sources == ['one', 'two', 'three']
 
+    def test_children(self):
+       """Test fetching the "children" of a Node.
+       """
+       node = SCons.Node.Node()
+       node.add_source(['one', 'two', 'three'])
+       node.add_dependency(['four', 'five', 'six'])
+       kids = node.children()
+       kids.sort()
+       print kids
+       assert kids == ['five', 'four', 'one', 'six', 'three', 'two']
+
 
 
 if __name__ == "__main__":
index 03afc2729269b433d28aa179170b19084f480df6..60269005b0c430e74f97df8596cef53b72955df6 100644 (file)
@@ -58,3 +58,6 @@ class Node:
         if type(source) is not type([]):
             raise TypeError("source must be a list")
        self.sources.extend(source)
+
+    def children(self):
+       return self.sources + self.depends