log.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # resulttool - Show logs
  2. #
  3. # Copyright (c) 2019 Garmin International
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms and conditions of the GNU General Public License,
  7. # version 2, as published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. # more details.
  13. #
  14. import resulttool.resultutils as resultutils
  15. def show_ptest(result, ptest, logger):
  16. if 'ptestresult.sections' in result:
  17. if ptest in result['ptestresult.sections'] and 'log' in result['ptestresult.sections'][ptest]:
  18. print(result['ptestresult.sections'][ptest]['log'])
  19. return 0
  20. print("ptest '%s' not found" % ptest)
  21. return 1
  22. def log(args, logger):
  23. results = resultutils.load_resultsdata(args.source)
  24. for path in results:
  25. for res in results[path]:
  26. if 'result' not in results[path][res]:
  27. continue
  28. r = results[path][res]['result']
  29. if args.raw:
  30. if 'ptestresult.rawlogs' in r:
  31. print(r['ptestresult.rawlogs']['log'])
  32. else:
  33. print('Raw logs not found')
  34. return 1
  35. for ptest in args.ptest:
  36. if not show_ptest(r, ptest, logger):
  37. return 1
  38. def register_commands(subparsers):
  39. """Register subcommands from this plugin"""
  40. parser = subparsers.add_parser('log', help='show logs',
  41. description='show the logs from test results',
  42. group='analysis')
  43. parser.set_defaults(func=log)
  44. parser.add_argument('source',
  45. help='the results file/directory/URL to import')
  46. parser.add_argument('--ptest', action='append', default=[],
  47. help='show logs for a ptest')
  48. parser.add_argument('--raw', action='store_true',
  49. help='show raw logs')