(node.__class__.__name__, str(node), klass.__name__)
return node
- def __doLookup(self, fsclass, name, directory=None):
+ def __doLookup(self, fsclass, name, directory = None, create = 1):
"""This method differs from the File and Dir factory methods in
one important way: the meaning of the directory parameter.
In this method, if directory is None or not supplied, the supplied
try:
directory = self.Root[drive_path]
except KeyError:
+ if not create:
+ raise UserError
dir = Dir(drive, ParentOfRoot())
dir.path = dir.path + os.sep
dir.abspath = dir.abspath + os.sep
directory = self.__checkClass(directory.entries[path_norm],
Dir)
except KeyError:
+ if not create:
+ raise UserError
dir_temp = Dir(path_name, directory)
directory.entries[path_norm] = dir_temp
directory.add_wkid(dir_temp)
try:
ret = self.__checkClass(directory.entries[file_name], fsclass)
except KeyError:
+ if not create:
+ raise UserError
ret = fsclass(path_comp[-1], directory)
directory.entries[file_name] = ret
directory.add_wkid(ret)
if not dir is None:
self._cwd = dir
- def Entry(self, name, directory = None):
+ def Entry(self, name, directory = None, create = 1):
"""Lookup or create a generic Entry node with the specified name.
If the name is a relative path (begins with ./, ../, or a file
name), then it is looked up relative to the supplied directory
construction time) if no directory is supplied.
"""
name, directory = self.__transformPath(name, directory)
- return self.__doLookup(Entry, name, directory)
+ return self.__doLookup(Entry, name, directory, create)
- def File(self, name, directory = None):
+ def File(self, name, directory = None, create = 1):
"""Lookup or create a File node with the specified name. If
the name is a relative path (begins with ./, ../, or a file name),
then it is looked up relative to the supplied directory node,
specified path.
"""
name, directory = self.__transformPath(name, directory)
- return self.__doLookup(File, name, directory)
+ return self.__doLookup(File, name, directory, create)
- def Dir(self, name, directory = None):
+ def Dir(self, name, directory = None, create = 1):
"""Lookup or create a Dir node with the specified name. If
the name is a relative path (begins with ./, ../, or a file name),
then it is looked up relative to the supplied directory node,
specified path.
"""
name, directory = self.__transformPath(name, directory)
- return self.__doLookup(Dir, name, directory)
+ return self.__doLookup(Dir, name, directory, create)
def BuildDir(self, build_dir, src_dir, duplicate=1):
"""Link the supplied build directory to the source directory
f1 = SCons.Node.FS.default_fs.File(test.workpath("binary_file"))
assert f1.get_contents() == "Foo\x1aBar", f1.get_contents()
+ def nonexistent(method, str):
+ try:
+ x = method(str, create = 0)
+ except UserError:
+ pass
+ else:
+ raise TestFailed, "did not catch expected UserError"
+
+ nonexistent(fs.Entry, 'nonexistent')
+ nonexistent(fs.Entry, 'nonexistent/foo')
+
+ nonexistent(fs.File, 'nonexistent')
+ nonexistent(fs.File, 'nonexistent/foo')
+
+ nonexistent(fs.Dir, 'nonexistent')
+ nonexistent(fs.Dir, 'nonexistent/foo')
+
#XXX test current() for directories
#XXX test sconsign() for directories
--- /dev/null
+#!/usr/bin/env python
+#
+# Copyright (c) 2001 Steven Knight
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import sys
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', "")
+
+test.run(arguments = 'foo',
+ stderr = "scons: *** Do not know how to make target `foo'. Stop.\n")
+
+test.run(arguments = '-k foo/bar foo',
+ stderr = """scons: *** Do not know how to make target `foo/bar'.
+scons: *** Do not know how to make target `foo'.
+""")
+
+test.pass_test()