merge.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #
  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. #
  15. import os
  16. import json
  17. import resulttool.resultutils as resultutils
  18. def merge(args, logger):
  19. if resultutils.is_url(args.target_results) or os.path.isdir(args.target_results):
  20. results = resultutils.load_resultsdata(args.target_results, configmap=resultutils.store_map)
  21. resultutils.append_resultsdata(results, args.base_results, configmap=resultutils.store_map)
  22. resultutils.save_resultsdata(results, args.target_results)
  23. else:
  24. results = resultutils.load_resultsdata(args.base_results, configmap=resultutils.flatten_map)
  25. if os.path.exists(args.target_results):
  26. resultutils.append_resultsdata(results, args.target_results, configmap=resultutils.flatten_map)
  27. resultutils.save_resultsdata(results, os.path.dirname(args.target_results), fn=os.path.basename(args.target_results))
  28. return 0
  29. def register_commands(subparsers):
  30. """Register subcommands from this plugin"""
  31. parser_build = subparsers.add_parser('merge', help='merge test result files/directories/URLs',
  32. description='merge the results from multiple files/directories/URLs into the target file or directory',
  33. group='setup')
  34. parser_build.set_defaults(func=merge)
  35. parser_build.add_argument('base_results',
  36. help='the results file/directory/URL to import')
  37. parser_build.add_argument('target_results',
  38. help='the target file or directory to merge the base_results with')