diff options
Diffstat (limited to 'scripts/lib/resulttool/log.py')
-rw-r--r-- | scripts/lib/resulttool/log.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/lib/resulttool/log.py b/scripts/lib/resulttool/log.py new file mode 100644 index 0000000000..5584f2d0a9 --- /dev/null +++ b/scripts/lib/resulttool/log.py | |||
@@ -0,0 +1,56 @@ | |||
1 | # resulttool - Show logs | ||
2 | # | ||
3 | # Copyright (c) 2019 Garmin International | ||
4 | # | ||
5 | # This program is free software; you can redistribute it and/or modify it | ||
6 | # under the terms and conditions of the GNU General Public License, | ||
7 | # version 2, as published by the Free Software Foundation. | ||
8 | # | ||
9 | # This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | # more details. | ||
13 | # | ||
14 | import resulttool.resultutils as resultutils | ||
15 | |||
16 | def show_ptest(result, ptest, logger): | ||
17 | if 'ptestresult.sections' in result: | ||
18 | if ptest in result['ptestresult.sections'] and 'log' in result['ptestresult.sections'][ptest]: | ||
19 | print(result['ptestresult.sections'][ptest]['log']) | ||
20 | return 0 | ||
21 | |||
22 | print("ptest '%s' not found" % ptest) | ||
23 | return 1 | ||
24 | |||
25 | def log(args, logger): | ||
26 | results = resultutils.load_resultsdata(args.source) | ||
27 | for path in results: | ||
28 | for res in results[path]: | ||
29 | if 'result' not in results[path][res]: | ||
30 | continue | ||
31 | r = results[path][res]['result'] | ||
32 | |||
33 | if args.raw: | ||
34 | if 'ptestresult.rawlogs' in r: | ||
35 | print(r['ptestresult.rawlogs']['log']) | ||
36 | else: | ||
37 | print('Raw logs not found') | ||
38 | return 1 | ||
39 | |||
40 | for ptest in args.ptest: | ||
41 | if not show_ptest(r, ptest, logger): | ||
42 | return 1 | ||
43 | |||
44 | def register_commands(subparsers): | ||
45 | """Register subcommands from this plugin""" | ||
46 | parser = subparsers.add_parser('log', help='show logs', | ||
47 | description='show the logs from test results', | ||
48 | group='analysis') | ||
49 | parser.set_defaults(func=log) | ||
50 | parser.add_argument('source', | ||
51 | help='the results file/directory/URL to import') | ||
52 | parser.add_argument('--ptest', action='append', default=[], | ||
53 | help='show logs for a ptest') | ||
54 | parser.add_argument('--raw', action='store_true', | ||
55 | help='show raw logs') | ||
56 | |||