Main function. Parses args, reads the log files and renders them as text or html.
()
| 27 | LogEvent = namedtuple('LogEvent', ['timestamp', 'source', 'event']) |
| 28 | |
| 29 | def main(): |
| 30 | """Main function. Parses args, reads the log files and renders them as text or html.""" |
| 31 | parser = argparse.ArgumentParser( |
| 32 | description=__doc__, formatter_class=argparse.RawTextHelpFormatter) |
| 33 | parser.add_argument( |
| 34 | 'testdir', nargs='?', default='', |
| 35 | help=('temporary test directory to combine logs from. ' |
| 36 | 'Defaults to the most recent')) |
| 37 | 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)') |
| 38 | parser.add_argument('--html', dest='html', action='store_true', help='outputs the combined log as html. Requires jinja2. pip install jinja2') |
| 39 | args = parser.parse_args() |
| 40 | |
| 41 | if args.html and args.color: |
| 42 | print("Only one out of --color or --html should be specified") |
| 43 | sys.exit(1) |
| 44 | |
| 45 | testdir = args.testdir or find_latest_test_dir() |
| 46 | |
| 47 | if not testdir: |
| 48 | print("No test directories found") |
| 49 | sys.exit(1) |
| 50 | |
| 51 | if not args.testdir: |
| 52 | print("Opening latest test directory: {}".format(testdir), file=sys.stderr) |
| 53 | |
| 54 | log_events = read_logs(testdir) |
| 55 | |
| 56 | print_logs(log_events, color=args.color, html=args.html) |
| 57 | |
| 58 | def read_logs(tmp_dir): |
| 59 | """Reads log files. |
no test coverage detected