csv_totals.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
  3. # All rights reserved.
  4. # This component and the accompanying materials are made available
  5. # under the terms of the License "Symbian Foundation License v1.0"
  6. # which accompanies this distribution, and is available
  7. # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
  8. #
  9. # Initial Contributors:
  10. # Nokia Corporation - initial contribution.
  11. #
  12. # Contributors:
  13. #
  14. # Description:
  15. """
  16. Summarise a .csv file (from the CSV filter) by adding up the numbers of
  17. errors, criticals, warnings and missing files for each component and each
  18. configuration.
  19. The output is another .csv file with the fourth field replaced by the total
  20. number of that "type" of event seen for that component and configuration.
  21. For example,
  22. error,/src/a/bld.inf,armv5_urel,64
  23. error,/src/a/bld.inf,armv5_udeb,64
  24. error,/src/b/bld.inf,armv5_urel,65
  25. error,/src/b/bld.inf,armv5_udeb,65
  26. """
  27. import os
  28. import sys
  29. import traceback
  30. # we don't expect arguments, so treat any as a call for help
  31. if len(sys.argv) > 1:
  32. print("usage:", sys.argv[0])
  33. print("""
  34. The input CSV is read from stdin. The expected format is,
  35. type,component,configuration,"commands and output text"
  36. The output CSV is written to sdtout. The output format is,
  37. type,component,configuration,number_of_occurences
  38. """)
  39. sys.exit(0)
  40. totals = {}
  41. line = " "
  42. while line:
  43. line = sys.stdin.readline().strip()
  44. if line:
  45. fields = line.split(",")
  46. key = ",".join(fields[0:3])
  47. if key in totals:
  48. totals[key] += 1
  49. else:
  50. totals[key] = 1
  51. for key, value in list(totals.items()):
  52. sys.stdout.write("{0},{1}\n".format(key, value))
  53. sys.exit(0)