Node: filesystem structure
Ant patterns for files and folders to exclude while doing the recursive traversal in waflib.Node.Node.ant_glob()
Bases: object
This class is organized in two parts:
Subclasses can provide a dict class to enable case insensitivity for example.
alias of dict
Note
Use Node.make_node() or Node.find_node() instead of calling this constructor
Provided to prevent nodes from being copied
Raises: | waflib.Errors.WafError |
---|
Reads and returns the contents of the file represented by this node, see waflib.Utils.readf():
def build(bld):
bld.path.find_node('wscript').read()
Parameters: |
|
---|---|
Return type: | string or bytes |
Returns: | File contents |
Writes data to the file represented by this node, see waflib.Utils.writef():
def build(bld):
bld.path.make_node('foo.txt').write('Hello, world!')
Parameters: |
|
---|
Reads and parses the contents of this node as JSON (Python ≥ 2.6):
def build(bld):
bld.path.find_node('abc.json').read_json()
Note that this by default automatically decodes unicode strings on Python2, unlike what the Python JSON module does.
Parameters: |
|
---|---|
Return type: | object |
Returns: | Parsed file contents |
Writes a python object as JSON to disk (Python ≥ 2.6) as UTF-8 data (JSON standard):
def build(bld):
bld.path.find_node('xyz.json').write_json(199)
Parameters: |
|
---|
Removes the file/folder from the filesystem (equivalent to rm -rf), and remove this object from the Node tree. Do not use this object after calling this method.
Returns the depth in the folder hierarchy from the filesystem root or from all the file drives
Returns: | filesystem depth |
---|---|
Return type: | integer |
Lists the folder contents
Returns: | list of file/folder names ordered alphabetically |
---|---|
Return type: | list of string |
Creates a folder represented by this node. Intermediate folders are created as needed.
Raises: | waflib.Errors.WafError when the folder is missing |
---|
Finds a node on the file system (files or folders), and creates the corresponding Node objects if it exists
Parameters: | lst (string or list of string) – relative path |
---|---|
Returns: | The corresponding Node object or None if no entry was found on the filesystem |
Return type: | :py:class:´waflib.Node.Node´ |
Returns or creates a Node object corresponding to the input path without considering the filesystem.
Parameters: | lst (string or list of string) – relative path |
---|---|
Return type: | :py:class:´waflib.Node.Node´ |
Returns a Node previously defined in the data structure. The filesystem is not considered.
Parameters: | lst (string or list of string) – relative path |
---|---|
Return type: | :py:class:´waflib.Node.Node´ or None if there is no entry in the Node datastructure |
Path of this node seen from the other:
def build(bld):
n1 = bld.path.find_node('foo/bar/xyz.txt')
n2 = bld.path.find_node('foo/stuff/')
n1.path_from(n2) # '../bar/xyz.txt'
Parameters: | node (waflib.Node.Node) – path to use as a reference |
---|---|
Returns: | a relative path or an absolute one if that is better |
Return type: | string |
Returns the absolute path. A cache is kept in the context as cache_node_abspath
Return type: | string |
---|
Returns whether the object belongs to a subtree of the input node:
def build(bld):
node = bld.path.find_node('wscript')
node.is_child_of(bld.path) # True
Parameters: | node (waflib.Node.Node) – path to use as a reference |
---|---|
Return type: | bool |
Recursive method used by waflib.Node.ant_glob().
Parameters: |
|
---|---|
Returns: | A generator object to iterate from |
Return type: | iterator |
Finds files across folders:
For example:
def configure(cfg):
cfg.path.ant_glob('**/*.cpp') # finds all .cpp files
cfg.root.ant_glob('etc/*.txt') # matching from the filesystem root can be slow
cfg.path.ant_glob('*.cpp', excl=['*.c'], src=True, dir=False)
For more information see http://ant.apache.org/manual/dirtasks.html
The nodes that correspond to files and folders that do not exist are garbage-collected. To prevent this behaviour in particular when running over the build directory, pass remove=False
Parameters: |
|
---|---|
Returns: | The corresponding Nodes |
Return type: | list of waflib.Node.Node instances |
Returns True if the node is below the source directory. Note that !is_src() ≠ is_bld()
Return type: | bool |
---|
Returns True if the node is below the build directory. Note that !is_bld() ≠ is_src()
Return type: | bool |
---|
Returns the corresponding Node object in the source directory (or self if not possible)
Return type: | waflib.Node.Node |
---|
Return the corresponding Node object in the build directory (or self if not possible)
Return type: | waflib.Node.Node |
---|
Use this method in the build phase to find source files corresponding to the relative path given.
First it looks up the Node data structure to find any declared Node object in the build directory. If None is found, it then considers the filesystem in the source directory.
Parameters: | lst (string or list of string) – relative path |
---|---|
Returns: | the corresponding Node object or None |
Return type: | waflib.Node.Node |
Use this method in the build phase to declare output files.
If ‘self’ is in build directory, it first tries to return an existing node object. If no Node is found, it tries to find one in the source directory. If no Node is found, a new Node object is created in the build directory, and the intermediate folders are added.
Parameters: | lst (string or list of string) – relative path |
---|
Searches for a folder on the filesystem (see waflib.Node.Node.find_node())
Parameters: | lst (string or list of string) – relative path |
---|---|
Returns: | The corresponding Node object or None if there is no such folder |
Return type: | waflib.Node.Node |
Declares a build node with a distinct extension; this is uses waflib.Node.Node.find_or_declare()
Returns: | A build node of the same path, but with a different extension |
---|---|
Return type: | waflib.Node.Node |
Returns the relative path seen from the build directory src/foo.cpp
Return type: | string |
---|
Returns the relative path seen from the source directory ../src/foo.cpp
Return type: | string |
---|
If a file in the build directory, returns waflib.Node.Node.bldpath(), else returns waflib.Node.Node.srcpath()
Return type: | string |
---|
Returns a signature (see waflib.Node.Node.h_file()) for the purpose of build dependency calculation. This method uses a per-context cache.
Returns: | a hash representing the object contents |
---|---|
Return type: | string or bytes |
Lock mandatory for thread-safe node serialization