blob: 7159463f6ed91af1644fe3fe0b6bae2e48a24536 [file] [log] [blame]
rjw91288f92022-11-01 13:59:36 +08001# 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#
6# This program is free software; you can redistribute it and/or modify it
7# under the terms and conditions of the GNU General Public License,
8# version 2, as published by the Free Software Foundation.
9#
10# This program is distributed in the hope it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13# more details.
14#
15import os
16import json
17import resulttool.resultutils as resultutils
18
19def merge(args, logger):
20 if resultutils.is_url(args.target_results) or os.path.isdir(args.target_results):
21 results = resultutils.load_resultsdata(args.target_results, configmap=resultutils.store_map)
22 resultutils.append_resultsdata(results, args.base_results, configmap=resultutils.store_map)
23 resultutils.save_resultsdata(results, args.target_results)
24 else:
25 results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map)
26 if os.path.exists(args.target_results):
27 resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map)
28 resultutils.save_resultsdata(results, os.path.dirname(args.target_results), fn=os.path.basename(args.target_results))
29
30 return 0
31
32def register_commands(subparsers):
33 """Register subcommands from this plugin"""
34 parser_build = subparsers.add_parser('merge', help='merge test result files/directories/URLs',
35 description='merge the results from multiple files/directories/URLs into the target file or directory',
36 group='setup')
37 parser_build.set_defaults(func=merge)
38 parser_build.add_argument('base_results',
39 help='the results file/directory/URL to import')
40 parser_build.add_argument('target_results',
41 help='the target file or directory to merge the base_results with')
42