tests/filtertraceback.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 17 Oct 2019 16:06:06 +0200
changeset 43302 f0a2c1972e81
parent 41462 9b2b8794f801
child 44654 d359f0d1a3d3
permissions -rwxr-xr-x
copies: simplify chain loop This is a mostly gratuitous change to make the code more direct. Differential Revision: https://phab.mercurial-scm.org/D7131

#!/usr/bin/env python

# Filters traceback lines from stdin.

from __future__ import absolute_import, print_function

import sys

state = 'none'

for line in sys.stdin:
    if state == 'none':
        if line.startswith('Traceback '):
            state = 'tb'

    elif state == 'tb':
        if line.startswith('  File '):
            state = 'file'
            continue

        elif not line.startswith(' '):
            state = 'none'

    elif state == 'file':
        # Ignore lines after "  File "
        state = 'tb'
        continue

    print(line, end='')