From: stevenknight Date: Fri, 22 Nov 2002 23:16:35 +0000 (+0000) Subject: Make File() and Dir() take a string for the second argument. (Anthony Roach) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=41b3a51c61ba6c8905e1aeb77a60fe5bdeabe128;p=scons.git Make File() and Dir() take a string for the second argument. (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@501 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 4f071a27..077f60b3 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -115,6 +115,9 @@ RELEASE 0.09 - - Make -U and Default('source') fail gracefully. + - Allow the File() and Dir() methods to take a path-name string as + the starting directory, in addition to a Dir object. + From sam th: - Dynamically check for the existence of utilities with which to diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 3e50d103..d66b7771 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -395,6 +395,8 @@ class FS: if isinstance(name, Entry): return self.__checkClass(name, klass) else: + if directory and not isinstance(directory, Dir): + directory = self.Dir(directory) name, directory = self.__transformPath(name, directory) return self.__doLookup(klass, name, directory, create) diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 9e6e095c..c817408e 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -907,7 +907,22 @@ class find_fileTestCase(unittest.TestCase): assert os.path.normpath('./foo') in file_names, file_names assert os.path.normpath('./bar/baz') in file_names, file_names +class StringDirTestCase(unittest.TestCase): + def runTest(self): + """Test using a string as the second argument of + File() and Dir()""" + test = TestCmd(workdir = '') + test.subdir('sub') + fs = SCons.Node.FS.FS(test.workpath('')) + + d = fs.Dir('sub', '.') + assert str(d) == 'sub' + assert d.exists() + f = fs.File('file', 'sub') + assert str(f) == os.path.join('sub', 'file') + assert not f.exists() + if __name__ == "__main__": suite = unittest.TestSuite() @@ -915,5 +930,6 @@ if __name__ == "__main__": suite.addTest(BuildDirTestCase()) suite.addTest(RepositoryTestCase()) suite.addTest(find_fileTestCase()) + suite.addTest(StringDirTestCase()) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1)