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