File: filtertraceback.py

package info (click to toggle)
mercurial 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,080 kB
  • sloc: python: 208,589; ansic: 56,460; tcl: 3,715; sh: 1,839; lisp: 1,483; cpp: 864; makefile: 769; javascript: 649; xml: 36
file content (28 lines) | stat: -rwxr-xr-x 548 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3

# Filters traceback lines from stdin.


import io
import sys

# Prevent \r from being inserted on Windows.
sys.stdout = io.TextIOWrapper(
    sys.stdout.buffer,
    sys.stdout.encoding,
    sys.stdout.errors,
    newline="\n",
    line_buffering=sys.stdout.line_buffering,
)

in_tb = False

for line in sys.stdin:
    do_print = not in_tb
    if line.startswith('Traceback '):
        in_tb = True
    elif not line.startswith(' '):
        in_tb = False
        do_print = True
    if do_print:
        print(line, end='')