blob: 3e4b7a38ad10bd5f57e1a02c7e0e4805a3ed90ce [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#
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 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',
35 description='merge the results from multiple files/directories 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 to import')
40 parser_build.add_argument('target_results',
41 help='the target file or directory to merge the base_results with')
42