Nodes

Node

class vcs.nodes.Node(path, kind)

Simplest class representing file or directory on repository. SCM backends should use FileNode and DirNode subclasses rather than Node directly.

Node’s path cannot start with slash as we operate on relative paths only. Moreover, every single node is identified by the path attribute, so it cannot end with slash, too. Otherwise, path could lead to mistakes.

get_parent_path()

Returns node’s parent path or empty string if node is root.

is_dir()

Returns True if node’s kind is NodeKind.DIR, False otherwise.

is_file()

Returns True if node’s kind is NodeKind.FILE, False otherwise.

is_root()

Returns True if node is a root node and False otherwise.

FileNode

class vcs.nodes.FileNode(path, content=None, changeset=None)

Class representing file nodes.

Attribute :path: path to the node, relative to repostiory’s root
Attribute :content: if given arbitrary sets content of the file
Attribute :changeset: if given, first time content is accessed, callback

Only one of content and changeset may be given. Passing both would raise NodeError exception.

Parameters:
  • path – relative path to the node
  • content – content may be passed to constructor
  • changeset – if given, will use it to lazily fetch content

RemovedFileNode

class vcs.nodes.RemovedFileNode(path)

Dummy FileNode class - trying to access any public attribute except path, name, kind or state (or methods/attributes checking those two) would raise RemovedFileNodeError.

Parameters:path – relative path to the node

DirNode

class vcs.nodes.DirNode(path, nodes=(), changeset=None)

DirNode stores list of files and directories within this node. Nodes may be used standalone but within repository context they lazily fetch data within same repositorty’s changeset.

Only one of nodes and changeset may be given. Passing both would raise NodeError exception.

Parameters:
  • path – relative path to the node
  • nodes – content may be passed to constructor
  • changeset – if given, will use it to lazily fetch content
  • size – always 0 for DirNode
get_node(path)

Returns node from within this particular DirNode, so it is now allowed to fetch, i.e. node located at ‘docs/api/index.rst’ from node ‘docs’. In order to access deeper nodes one must fetch nodes between them first - this would work:

docs = root.get_node('docs')
docs.get_node('api').get_node('index.rst')
Param :path - relative to the current node

Note

To access lazily (as in example above) node have to be initialized with related changeset object - without it node is out of context and may know nothing about anything else than nearest (located at same level) nodes.

RootNode

class vcs.nodes.RootNode(nodes=(), changeset=None)

DirNode being the root node of the repository.

Table Of Contents

Previous topic

API Reference

Next topic

Backends

This Page