Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 1 | # resulttool - merge multiple testresults.json files into a file or directory |
| 2 | # |
| 3 | # Copyright (c) 2019, Intel Corporation. |
| 4 | # Copyright (c) 2019, Linux Foundation |
| 5 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 6 | # SPDX-License-Identifier: GPL-2.0-only |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 7 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 8 | |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 9 | import os |
| 10 | import json |
| 11 | import resulttool.resultutils as resultutils |
| 12 | |
| 13 | def merge(args, logger): |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 14 | configvars = {} |
| 15 | if not args.not_add_testseries: |
| 16 | configvars = resultutils.extra_configvars.copy() |
| 17 | if args.executed_by: |
| 18 | configvars['EXECUTED_BY'] = args.executed_by |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 19 | if resultutils.is_url(args.target_results) or os.path.isdir(args.target_results): |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 20 | results = resultutils.load_resultsdata(args.target_results, configmap=resultutils.store_map, configvars=configvars) |
| 21 | resultutils.append_resultsdata(results, args.base_results, configmap=resultutils.store_map, configvars=configvars) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 22 | resultutils.save_resultsdata(results, args.target_results) |
| 23 | else: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 24 | results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map, configvars=configvars) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 25 | if os.path.exists(args.target_results): |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 26 | resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map, configvars=configvars) |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 27 | resultutils.save_resultsdata(results, os.path.dirname(args.target_results), fn=os.path.basename(args.target_results)) |
| 28 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 29 | logger.info('Merged results to %s' % os.path.dirname(args.target_results)) |
| 30 | |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 31 | return 0 |
| 32 | |
| 33 | def register_commands(subparsers): |
| 34 | """Register subcommands from this plugin""" |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 35 | parser_build = subparsers.add_parser('merge', help='merge test result files/directories/URLs', |
| 36 | description='merge the results from multiple files/directories/URLs into the target file or directory', |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 37 | group='setup') |
| 38 | parser_build.set_defaults(func=merge) |
| 39 | parser_build.add_argument('base_results', |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 40 | help='the results file/directory/URL to import') |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 41 | parser_build.add_argument('target_results', |
| 42 | help='the target file or directory to merge the base_results with') |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 43 | parser_build.add_argument('-t', '--not-add-testseries', action='store_true', |
| 44 | help='do not add testseries configuration to results') |
| 45 | parser_build.add_argument('-x', '--executed-by', default='', |
| 46 | help='add executed-by configuration to each result file') |