Commit 6c4b69e0 authored by Dominik Charousset's avatar Dominik Charousset

Add filtering option to indentation script

parent cdfe2c22
...@@ -6,29 +6,55 @@ ...@@ -6,29 +6,55 @@
# usage (read file): indent_trace_log.py FILENAME # usage (read file): indent_trace_log.py FILENAME
# (read stdin): indent_trace_log.py - # (read stdin): indent_trace_log.py -
import sys import argparse, sys, os, fileinput, re
import os
import fileinput
def read_lines(fp): def is_entry(line):
return 'TRACE' in line and 'ENTRY' in line
def is_exit(line):
return 'TRACE' in line and 'EXIT' in line
def print_indented(line, indent):
if is_exit(line):
indent = indent[:-2]
sys.stdout.write(indent)
sys.stdout.write(line)
if is_entry(line):
indent += " "
return indent
def read_lines(fp, ids):
indent = "" indent = ""
for line in fp: if len(ids) == 0:
if 'TRACE' in line and 'EXIT' in line: for line in fp:
indent = indent[:-2] indent = print_indented(line, indent)
sys.stdout.write(indent) else:
sys.stdout.write(line) rx = re.compile('.+ (?:actor|ID = )([0-9]+) .+')
if 'TRACE' in line and 'ENTRY' in line: for line in fp:
indent += " " rx_res = rx.match(line)
if rx_res != None and rx_res.group(1) in ids:
indent = print_indented(line, indent)
def read_ids(ids_file):
if os.path.isfile(ids_file):
with open(ids_file) as fp:
return fp.read().splitlines()
return []
def main(): def main():
filepath = sys.argv[1] parser = argparse.ArgumentParser(description='Add a new C++ class.')
parser.add_argument('-i', dest='ids_file', help='only include actors with IDs from file')
parser.add_argument("log", help='path to the log file or "-" for reading from STDIN')
args = parser.parse_args()
filepath = args.log
ids = read_ids(args.ids_file)
if filepath == '-': if filepath == '-':
read_lines(fileinput.input()) read_lines(fileinput.input(), ids)
else: else:
if not os.path.isfile(filepath): if not os.path.isfile(filepath):
sys.exit() sys.exit()
with open(filepath) as fp: with open(filepath) as fp:
read_lines(fp) read_lines(fp, ids)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment