Utils

This module provides some useful tools for vcs like annotate/diff html output. It also includes some internal helpers.

Public API

Private API

Annotate utils

vcs.utils.annotate.annotate_highlight(filenode, annotate_from_changeset_func=None, order=None, headers=None, **options)

Returns html portion containing annotated table with 3 columns: line numbers, changeset information and pygmentized line of code.

Parameters:
  • filenode – FileNode object
  • annotate_from_changeset_func – function taking changeset and returning single annotate cell; needs break line at the end
  • order – ordered sequence of ls (line numbers column), annotate (annotate column), code (code column); Default is ['ls', 'annotate', 'code']
  • headers – dictionary with headers (keys are whats in order parameter)

Diffs utils

class vcs.utils.diffs.DiffProcessor(udiff, differ='udiff')

Give it a unified diff and it returns a list of the files that were mentioned in the diff together with a dict of meta information that can be used to render it in a HTML template.

Parameters:
  • udiff – a text in udiff format
as_html(table_class='code-difftable', line_class='line', new_lineno_class='lineno old', old_lineno_class='lineno new', code_class='code')

Return udiff as html table with customized css classes

copy_iterator()

make a fresh copy of generator, we should not iterate thru an original as it’s needed for repeating operations on this instance of DiffProcessor

prepare()

Prepare the passed udiff for HTML rendering. It’l return a list of dicts

raw_diff()

Returns raw string as udiff

vcs.utils.diffs.get_udiff(filenode_old, filenode_new)

Returns unified diff between given filenode_old and filenode_new.

Lazy attributes utils

vcs.utils.lazy.LazyProperty

Decorator for easier creation of property from potentially expensive to calculate attribute of the class.

Usage:

class Foo(object):
    @LazyProperty
    def bar(self):
        print 'Calculating self._bar'
        return 42

Taken from http://blog.pythonisito.com/2008/08/lazy-descriptors.html and used widely.

Table Of Contents

Previous topic

Mercurial Backend

Next topic

Web

This Page