Commits

Steven Knight  committed d010ef3

Add children() methods for nodes.

  • Participants
  • Parent commits e116aea

Comments (0)

Files changed (4)

File src/engine/SCons/Node/FS.py

         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

File src/engine/SCons/Node/FSTests.py

         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
 

File src/engine/SCons/Node/NodeTests.py

 	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__":

File src/engine/SCons/Node/__init__.py

         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