summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Node
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/Node')
-rw-r--r--src/engine/SCons/Node/FS.py20
-rw-r--r--src/engine/SCons/Node/FSTests.py22
2 files changed, 41 insertions, 1 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index 7c30333..a047903 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -355,6 +355,22 @@ class Entry(SCons.Node.Node):
else:
return self.srcpath
+ def get_contents(self):
+ """Fetch the contents of the entry.
+
+ Since this should return the real contents from the file
+ system, we check to see into what sort of subclass we should
+ morph this Entry."""
+ if os.path.isfile(self.abspath):
+ self.__class__ = File
+ self._morph()
+ return File.get_contents(self)
+ if os.path.isdir(self.abspath):
+ self.__class__ = Dir
+ self._morph()
+ return Dir.get_contents(self)
+ raise AttributeError
+
def exists(self):
return os.path.exists(str(self))
@@ -477,6 +493,10 @@ class Dir(Entry):
"""A directory has no signature."""
pass
+ def get_contents(self):
+ """Return a fixed "contents" value of a directory."""
+ return ''
+
def current(self):
"""If all of our children were up-to-date, then this
directory was up-to-date, too."""
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index ee82563..6151f2d 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -479,7 +479,27 @@ class FSTestCase(unittest.TestCase):
#XXX test root()
- #XXX test get_contents()
+ # test Entry.get_contents()
+ e = fs.Entry('does_not_exist')
+ exc_caught = 0
+ try:
+ e.get_contents()
+ except AttributeError:
+ exc_caught = 1
+ assert exc_caught, "Should have caught an AttributError"
+
+ test.write("file", "file\n")
+ e = fs.Entry('file')
+ c = e.get_contents()
+ assert c == "file\n", c
+ assert e.__class__ == SCons.Node.FS.File
+ test.unlink("file")
+
+ test.subdir("dir")
+ e = fs.Entry('dir')
+ c = e.get_contents()
+ assert c == "", c
+ assert e.__class__ == SCons.Node.FS.Dir
#XXX test get_timestamp()