outputhelper.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #
  2. # This file is part of stov, written by Helmut Pozimski in 2012.
  3. #
  4. # stov is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, version 2 of the License.
  7. #
  8. # stov is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with stov. If not, see <http://www.gnu.org/licenses/>.
  15. # -*- coding: utf8 -*-
  16. from __future__ import unicode_literals, print_function
  17. import sys
  18. """
  19. A little helper function used to do some additional checks before actually
  20. using print to generate the output"""
  21. def printf(string, outputlevel, descriptor="stdout", level="default"):
  22. if descriptor == "stdout":
  23. if level == "default" and outputlevel == "default":
  24. if sys.version_info >= (3, 0):
  25. print(string)
  26. else:
  27. print(string.encode("utf8"))
  28. elif level == "verbose":
  29. if sys.version_info >= (3, 0):
  30. print(string)
  31. else:
  32. print(string.encode("utf8"))
  33. elif level == "quiet":
  34. pass
  35. elif descriptor == "stderr":
  36. if level == "default" and outputlevel == "default":
  37. if sys.version_info >= (3, 0):
  38. print (string, file=sys.stderr)
  39. else:
  40. print(string.encode("utf8"), file=sys.stderr)
  41. elif level == "verbose":
  42. if sys.version_info >= (3, 0):
  43. print (string, file=sys.stderr)
  44. else:
  45. print(string.encode("utf8"), file=sys.stderr)
  46. elif level == "quiet":
  47. pass