From 4e2760ad9962bc0d67daaa8a31c64d774ba578db Mon Sep 17 00:00:00 2001 From: stevenknight Date: Tue, 2 Oct 2001 13:11:42 +0000 Subject: [PATCH] Add children() methods for nodes. git-svn-id: http://scons.tigris.org/svn/scons/trunk@81 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Node/FS.py | 5 +++++ src/engine/SCons/Node/FSTests.py | 12 ++++++++++++ src/engine/SCons/Node/NodeTests.py | 11 +++++++++++ src/engine/SCons/Node/__init__.py | 3 +++ 4 files changed, 31 insertions(+) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 25957661..2950c978 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -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 diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 1cffd8c8..568022bd 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -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 diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index 26cf6bda..3ea6d7f4 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -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__": diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 03afc272..60269005 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -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 -- 2.26.2