vcs 0.4.0 documentation

This Page

vcs.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.

is_submodule()

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

name

Returns name of the node so if its path then only last part is returned.

FileNode

class vcs.nodes.FileNode(path, content=None, changeset=None, mode=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
Attribute :mode: octal stat mode for a node. Default is 0100644.

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
  • mode – octal representation of ST_MODE (i.e. 0100644)
annotate

Returns a list of three element tuples with lineno,changeset and line

content

Returns lazily content of the FileNode. If possible, would try to decode content from UTF-8.

extension

Returns filenode extension

get_mimetype()

Mimetype is calculated based on the file’s content. If _mimetype attribute is available, it will be returned (backends which store mimetypes or can easily recognize them, should set this private attribute to indicate that type should NOT be calculated).

history

Returns a list of changeset for this file in which the file was changed

is_binary

Returns True if file has binary content.

is_executable()

Returns True if file has executable flag turned on.

lexer

Returns pygment’s lexer class. Would try to guess lexer taking file’s content, name and mimetype.

lexer_alias

Returns first alias of the lexer guessed for this file.

mimetype

Wrapper around full mimetype info. It returns only type of fetched mimetype without the encoding part. use get_mimetype function to fetch full set of (type,encoding)

mode

Returns lazily mode of the FileNode. If changeset is not set, would use value given at initialization or 0100644 (default).

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.