blob: 70d23a48fdcb70dc8bb61fd755a793f89d1ebe23 [file] [log] [blame]
Brad Bishop40320b12019-03-26 16:08:25 -04001# 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 Bishopc342db32019-05-15 21:57:59 -04006# SPDX-License-Identifier: GPL-2.0-only
Brad Bishop40320b12019-03-26 16:08:25 -04007#
Brad Bishopc342db32019-05-15 21:57:59 -04008
Brad Bishop40320b12019-03-26 16:08:25 -04009import os
10import json
11import resulttool.resultutils as resultutils
12
13def merge(args, logger):
Brad Bishopc342db32019-05-15 21:57:59 -040014 if resultutils.is_url(args.target_results) or os.path.isdir(args.target_results):
Brad Bishop40320b12019-03-26 16:08:25 -040015 results = resultutils.load_resultsdata(args.target_results, configmap=resultutils.store_map)
16 resultutils.append_resultsdata(results, args.base_results, configmap=resultutils.store_map)
17 resultutils.save_resultsdata(results, args.target_results)
18 else:
19 results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map)
20 if os.path.exists(args.target_results):
21 resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map)
22 resultutils.save_resultsdata(results, os.path.dirname(args.target_results), fn=os.path.basename(args.target_results))
23
24 return 0
25
26def register_commands(subparsers):
27 """Register subcommands from this plugin"""
Brad Bishopc342db32019-05-15 21:57:59 -040028 parser_build = subparsers.add_parser('merge', help='merge test result files/directories/URLs',
29 description='merge the results from multiple files/directories/URLs into the target file or directory',
Brad Bishop40320b12019-03-26 16:08:25 -040030 group='setup')
31 parser_build.set_defaults(func=merge)
32 parser_build.add_argument('base_results',
Brad Bishopc342db32019-05-15 21:57:59 -040033 help='the results file/directory/URL to import')
Brad Bishop40320b12019-03-26 16:08:25 -040034 parser_build.add_argument('target_results',
35 help='the target file or directory to merge the base_results with')
36