pgtoolkit/colordiff.py
author Radek Brich <radek.brich@devl.cz>
Thu, 31 Jan 2013 13:24:57 +0100
changeset 63 8c7f0a51ba50
permissions -rw-r--r--
PgDiff, schemadiff.py: Add function filter. Add --body parameter to diff function source.

from subprocess import Popen, PIPE


def colordiff(diff):
    """Colorize diff output using external program colordiff"""
    try:
        p = Popen(["colordiff"], stdin=PIPE, stdout=PIPE, close_fds=True)
        outs, _errs = p.communicate(diff.encode('utf8'))
        return outs.decode('utf8')
    except OSError:
        return diff