Main function. Parses args, reads the log files and renders them as text or html.
()
| 31 | LogEvent = namedtuple('LogEvent', ['timestamp', 'source', 'event']) |
| 32 | |
| 33 | def main(): |
| 34 | """Main function. Parses args, reads the log files and renders them as text or html.""" |
| 35 | parser = argparse.ArgumentParser( |
| 36 | description=__doc__, formatter_class=argparse.RawTextHelpFormatter) |
| 37 | parser.add_argument( |
| 38 | 'testdir', nargs='?', default='', |
| 39 | help=('temporary test directory to combine logs from. ' |
| 40 | 'Defaults to the most recent')) |
| 41 | parser.add_argument('-c', '--color', dest='color', action='store_true', help='outputs the combined log with events colored by source (requires posix terminal colors. Use less -r for viewing)') |
| 42 | parser.add_argument('--html', dest='html', action='store_true', help='outputs the combined log as html. Requires jinja2. pip install jinja2') |
| 43 | parser.add_argument('--chain', dest='chain', help='selected chain in the tests (default: elementsregtest)', default='elementsregtest') |
| 44 | args = parser.parse_args() |
| 45 | |
| 46 | if args.html and args.color: |
| 47 | print("Only one out of --color or --html should be specified") |
| 48 | sys.exit(1) |
| 49 | |
| 50 | testdir = args.testdir or find_latest_test_dir() |
| 51 | |
| 52 | if not testdir: |
| 53 | print("No test directories found") |
| 54 | sys.exit(1) |
| 55 | |
| 56 | if not args.testdir: |
| 57 | print("Opening latest test directory: {}".format(testdir), file=sys.stderr) |
| 58 | |
| 59 | colors = defaultdict(lambda: '') |
| 60 | if args.color: |
| 61 | colors["test"] = "\033[0;36m" # CYAN |
| 62 | colors["node0"] = "\033[0;34m" # BLUE |
| 63 | colors["node1"] = "\033[0;32m" # GREEN |
| 64 | colors["node2"] = "\033[0;31m" # RED |
| 65 | colors["node3"] = "\033[0;33m" # YELLOW |
| 66 | colors["reset"] = "\033[0m" # Reset font color |
| 67 | |
| 68 | log_events = read_logs(testdir, args.chain) |
| 69 | |
| 70 | if args.html: |
| 71 | print_logs_html(log_events) |
| 72 | else: |
| 73 | print_logs_plain(log_events, colors) |
| 74 | print_node_warnings(testdir, colors) |
| 75 | |
| 76 | |
| 77 | def read_logs(tmp_dir, chain): |
no test coverage detected