poky/scripts/lib/resulttool/log.py
Richard Purdie ffae400179 meta/lib+scripts: Convert to SPDX license headers
This adds SPDX license headers in place of the wide assortment of things
currently in our script headers. We default to GPL-2.0-only except for the
oeqa code where it was clearly submitted and marked as MIT on the most part
or some scripts which had the "or later" GPL versioning.

The patch also drops other obsolete bits of file headers where they were
encoountered such as editor modelines, obsolete maintainer information or
the phrase "All rights reserved" which is now obsolete and not required in
copyright headers (in this case its actually confusing for licensing as all
rights were not reserved).

More work is needed for OE-Core but this takes care of the bulk of the scripts
and meta/lib directories.

The top level LICENSE files are tweaked to match the new structure and the
SPDX naming.

(From OE-Core rev: f8c9c511b5f1b7dbd45b77f345cb6c048ae6763e)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-05-09 16:31:55 +01:00

72 lines
2.8 KiB
Python

# resulttool - Show logs
#
# Copyright (c) 2019 Garmin International
#
# SPDX-License-Identifier: GPL-2.0-only
#
import os
import resulttool.resultutils as resultutils
def show_ptest(result, ptest, logger):
if 'ptestresult.sections' in result:
if ptest in result['ptestresult.sections'] and 'log' in result['ptestresult.sections'][ptest]:
print(result['ptestresult.sections'][ptest]['log'])
return 0
print("ptest '%s' not found" % ptest)
return 1
def log(args, logger):
results = resultutils.load_resultsdata(args.source)
ptest_count = sum(1 for _, _, _, r in resultutils.test_run_results(results) if 'ptestresult.sections' in r)
if ptest_count > 1 and not args.prepend_run:
print("%i ptest sections found. '--prepend-run' is required" % ptest_count)
return 1
for _, run_name, _, r in resultutils.test_run_results(results):
if args.dump_ptest:
if 'ptestresult.sections' in r:
for name, ptest in r['ptestresult.sections'].items():
if 'log' in ptest:
dest_dir = args.dump_ptest
if args.prepend_run:
dest_dir = os.path.join(dest_dir, run_name)
os.makedirs(dest_dir, exist_ok=True)
dest = os.path.join(dest_dir, '%s.log' % name)
print(dest)
with open(dest, 'w') as f:
f.write(ptest['log'])
if args.raw:
if 'ptestresult.rawlogs' in r:
print(r['ptestresult.rawlogs']['log'])
else:
print('Raw logs not found')
return 1
for ptest in args.ptest:
if not show_ptest(r, ptest, logger):
return 1
def register_commands(subparsers):
"""Register subcommands from this plugin"""
parser = subparsers.add_parser('log', help='show logs',
description='show the logs from test results',
group='analysis')
parser.set_defaults(func=log)
parser.add_argument('source',
help='the results file/directory/URL to import')
parser.add_argument('--ptest', action='append', default=[],
help='show logs for a ptest')
parser.add_argument('--dump-ptest', metavar='DIR',
help='Dump all ptest log files to the specified directory.')
parser.add_argument('--prepend-run', action='store_true',
help='''Dump ptest results to a subdirectory named after the test run when using --dump-ptest.
Required if more than one test run is present in the result file''')
parser.add_argument('--raw', action='store_true',
help='show raw logs')