Node

Node: filesystem structure, contains lists of nodes

  1. Each file/folder is represented by exactly one node.
  2. Some potential class properties are stored on waflib.Build.BuildContext : nodes to depend on, etc. Unused class members can increase the .wafpickle file size sensibly.
  3. Node objects should never be created directly, use the methods Node.make_node() or Node.find_node()
  4. The methods Node.find_resource(), Node.find_dir() Node.find_or_declare() should be used when a build context is present
  5. Each instance of waflib.Context.Context has a unique Node subclass. (waflib.Node.Nod3, see the waflib.Context.Context initializer). A reference to the context owning a node is held as self.ctx
waflib.Node.exclude_regs

Ant patterns for files and folders to exclude while doing the recursive traversal in waflib.Node.Node.ant_glob()

waflib.Node.split_path(path)[source]

Split a path by os.sep (This is not os.path.split)

Parameters:path (string) – path to split
Return type:list of string
Returns:the path, split
class waflib.Node.Node(name, parent)[source]

Bases: object

This class is organized in two parts

  • The basic methods meant for filesystem access (compute paths, create folders, etc)
  • The methods bound to a waflib.Build.BuildContext (require bld.srcnode and bld.bldnode)
__setstate__(data)[source]

Deserializes from data

__getstate__()[source]

Serialize the node info

__str__()[source]

String representation (name), for debugging purposes

__repr__()[source]

String representation (abspath), for debugging purposes

__hash__()[source]

Node hash, used for storage in dicts. This hash is not persistent.

__eq__(node)[source]

Node comparison, based on the IDs

__copy__()[source]

Implemented to prevent nodes from being copied (raises an exception)

read(flags='r')[source]

Return the contents of the file represented by this node:

def build(bld):
        bld.path.find_node('wscript').read()
Parameters:
  • fname (string) – Path to file
  • m (string) – Open mode
Return type:

string

Returns:

File contents

write(data, flags='w')[source]

Write some text to the physical file represented by this node:

def build(bld):
        bld.path.make_node('foo.txt').write('Hello, world!')
Parameters:
  • data (string) – data to write
  • flags (string) – Write mode
chmod(val)[source]

Change file/dir permissions:

def build(bld):
        bld.path.chmod(493) # 0755
delete()[source]

Delete the file/folder physically (but not the node)

suffix()[source]

Return the file extension

height()[source]

Depth in the folder hierarchy from the filesystem root or from all the file drives

listdir()[source]

List the folder contents

mkdir()[source]

Create a folder represented by this node, creating intermediate nodes as needed An exception will be raised only when the folder cannot possibly exist there

find_node(lst)[source]

Find a node on the file system (files or folders), create intermediate nodes as needed

Parameters:lst (string or list of string) – path
make_node(lst)[source]

Find or create a node without looking on the filesystem

Parameters:lst (string or list of string) – path
search(lst)[source]

Search for a node without looking on the filesystem

Parameters:lst (string or list of string) – path
path_from(node)[source]

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
abspath()[source]

Absolute path. A cache is kept in the context as cache_node_abspath

is_child_of(node)[source]

Does this node belong to the subtree 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
ant_iter(accept=None, maxdepth=25, pats=[], dir=False, src=True, remove=True)[source]

Semi-private and recursive method used by ant_glob.

Parameters:
  • accept (function) – function used for accepting/rejecting a node, returns the patterns that can be still accepted in recursion
  • maxdepth (int) – maximum depth in the filesystem (25)
  • pats (tuple) – list of patterns to accept and list of patterns to exclude
  • dir (bool) – return folders too (False by default)
  • src (bool) – return files (True by default)
  • remove (bool) – remove files/folders that do not exist (True by default)
ant_glob(*k, **kw)[source]

This method is used for finding files across folders. It behaves like ant patterns:

  • **/* find all files recursively
  • **/*.class find all files ending by .class
  • .. find files having two dot characters

For example:

def configure(cfg):
        cfg.path.ant_glob('**/*.cpp') # find all .cpp files
        cfg.root.ant_glob('etc/*.txt') # using 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 will be removed

Parameters:
  • incl (string or list of strings) – ant patterns or list of patterns to include
  • excl (string or list of strings) – ant patterns or list of patterns to exclude
  • dir (bool) – return folders too (False by default)
  • src (bool) – return files (True by default)
  • remove (bool) – remove files/folders that do not exist (True by default)
  • maxdepth (int) – maximum depth of recursion
is_src()[source]

True if the node is below the source directory note: !is_src does not imply is_bld()

Return type:bool
is_bld()[source]

True if the node is below the build directory note: !is_bld does not imply is_src

Return type:bool
get_src()[source]

Return the equivalent src node (or self if not possible)

Return type:waflib.Node.Node
get_bld()[source]

Return the equivalent bld node (or self if not possible)

Return type:waflib.Node.Node
find_resource(lst)[source]

Try to find a declared build node or a source file

Parameters:lst (string or list of string) – path
find_or_declare(lst)[source]

if ‘self’ is in build directory, try to return an existing node if no node is found, go to the source directory try to find an existing node in the source directory if no node is found, create it in the build directory

Parameters:lst (string or list of string) – path
find_dir(lst)[source]

Search for a folder in the filesystem

Parameters:lst (string or list of string) – path
change_ext(ext, ext_in=None)[source]
Returns:A build node of the same path, but with a different extension
Return type:waflib.Node.Node
nice_path(env=None)[source]

Return the path seen from the launch directory. It is often used for printing nodes in the console to open files easily.

Parameters:env – unused, left for compatibility with waf 1.5
bldpath()[source]

Path seen from the build directory default/src/foo.cpp

srcpath()[source]

Path seen from the source directory ../src/foo.cpp

relpath()[source]

If a file in the build directory, bldpath, else srcpath

bld_dir()[source]

Build path without the file name

bld_base()[source]

Build path without the extension: src/dir/foo(.cpp)

get_bld_sig()[source]

Node signature, assuming the file is in the build directory

waflib.Node.pickle_lock

Lock mandatory for thread-safe node serialization

Previous topic

Logs

Next topic

Options

This Page