output.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ################################################################################
  2. # $Id: output.py 2552 2007-02-08 21:40:46Z b4rt $
  3. # $Date: 2007-02-08 15:40:46 -0600 (Thu, 08 Feb 2007) $
  4. # $Revision: 2552 $
  5. ################################################################################
  6. # #
  7. # LICENSE #
  8. # #
  9. # This program is free software; you can redistribute it and/or #
  10. # modify it under the terms of the GNU General Public License (GPL) #
  11. # as published by the Free Software Foundation; either version 2 #
  12. # of the License, or (at your option) any later version. #
  13. # #
  14. # This program is distributed in the hope that it will be useful, #
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  17. # GNU General Public License for more details. #
  18. # #
  19. # To read the license please visit http://www.gnu.org/copyleft/gpl.html #
  20. # #
  21. # #
  22. ################################################################################
  23. # standard-imports
  24. import sys
  25. import time
  26. ################################################################################
  27. """ ------------------------------------------------------------------------ """
  28. """ getPrefix """
  29. """ ------------------------------------------------------------------------ """
  30. def getPrefix():
  31. return time.strftime('[%Y/%m/%d - %H:%M:%S]') + " "
  32. """ ------------------------------------------------------------------------ """
  33. """ getOutput """
  34. """ ------------------------------------------------------------------------ """
  35. def getOutput(message):
  36. return getPrefix() + message + "\n"
  37. """ ------------------------------------------------------------------------ """
  38. """ printMessage """
  39. """ ------------------------------------------------------------------------ """
  40. def printMessage(message):
  41. sys.stdout.write(getOutput(message))
  42. sys.stdout.flush()
  43. """ ------------------------------------------------------------------------ """
  44. """ printError """
  45. """ ------------------------------------------------------------------------ """
  46. def printError(message):
  47. sys.stderr.write(getOutput(message))
  48. sys.stderr.flush()
  49. """ ------------------------------------------------------------------------ """
  50. """ printException """
  51. """ ------------------------------------------------------------------------ """
  52. def printException():
  53. print getPrefix(), sys.exc_info()
  54. sys.stdout.flush()