sbs_filter.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/python
  2. # Copyright (c) 2010-2011 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. import os
  17. import sys
  18. import traceback
  19. # intercept the -h option
  20. if "-h" in sys.argv or "--help" in sys.argv:
  21. print("usage: {0} [sbs options]".format(sys.argv[0]))
  22. print(" The log data is read from stdin.")
  23. print(" Type 'sbs -h' for a list of sbs options.")
  24. sys.exit(0)
  25. import sbs_env
  26. # now we should be able to find the raptor modules
  27. import raptor.build
  28. import raptor.pluginbox
  29. # make sure that HOSTPLATFORM is set
  30. if not "HOSTPLATFORM" in os.environ:
  31. sys.stderr.write("HOSTPLATFORM is not set ... try running gethost.sh\n")
  32. sys.exit(1)
  33. if not "HOSTPLATFORM_DIR" in os.environ:
  34. sys.stderr.write("HOSTPLATFORM_DIR is not set ... try running gethost.sh\n")
  35. sys.exit(1)
  36. # construct a Raptor object from our command-line (less the name of this script)
  37. the_raptor = raptor.build.Raptor.CreateCommandlineAnalysis(sys.argv[1:])
  38. # from Raptor.OpenLog()
  39. try:
  40. # Find all the raptor plugins and put them into a pluginbox.
  41. if not the_raptor.systemPlugins.isAbsolute():
  42. the_raptor.systemPlugins = the_raptor.home.Append(the_raptor.systemPlugins)
  43. pbox = raptor.pluginbox.PluginBox(str(the_raptor.systemPlugins))
  44. raptor_params = raptor.build.BuildStats(the_raptor)
  45. # Open the requested plugins using the pluginbox
  46. the_raptor.out.open(raptor_params, the_raptor.filterList, pbox)
  47. except ValueError as e:
  48. sys.stderr.write("error: problem while creating filters: {0}\n".format(str(e)))
  49. sys.exit(1)
  50. except Exception as e:
  51. # Unrecognised exception: print a traceback
  52. sys.stderr.write("error: problem while creating filters: {0}\n".format(str(e)))
  53. traceback.print_exc()
  54. sys.exit(1)
  55. # read stdin a line at a time and pass it to the Raptor object
  56. try:
  57. line = " "
  58. while line:
  59. line = sys.stdin.readline()
  60. the_raptor.out.write(line)
  61. except Exception as e:
  62. sys.stderr.write("error: problem while filtering: %s\n" % str(e))
  63. traceback.print_exc()
  64. sys.exit(1)
  65. # Print the summary (this can't return errors)
  66. the_raptor.out.summary()
  67. if not the_raptor.out.close():
  68. the_raptor.errorCode = 2
  69. # return the error code
  70. sys.exit(the_raptor.errorCode)