12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #
- # This file is part of stov, written by Helmut Pozimski in 2012.
- #
- # stov is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, version 2 of the License.
- #
- # stov is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with stov. If not, see <http://www.gnu.org/licenses/>.
- # -*- coding: utf8 -*-
- import sys
- """
- A little helper function used to do some additional checks before actually
- using print to generate the output"""
- def printf(string, outputlevel, descriptor="stdout", level="default"):
- if descriptor == "stdout":
- if level == "default" and outputlevel == "default":
- if isinstance(string, unicode):
- print string.encode("utf8")
- elif string is str:
- print string
- else:
- print str(string)
- elif level == "verbose":
- if isinstance(string, unicode):
- print string.encode("utf8")
- elif string is str:
- print string
- else:
- print str(string)
- elif level == "quiet":
- pass
- elif descriptor == "stderr":
- if level == "default" and outputlevel == "default":
- if isinstance(string, unicode):
- print >> sys.stderr, string.encode("utf8")
- elif string is str:
- print >> sys.stderr, string
- else:
- print str(string)
- elif level == "verbose":
- if isinstance(string, unicode):
- print >> sys.stderr, string.encode("utf8")
- elif string is str:
- print >> sys.stderr, string
- else:
- print >> sys.stderr, str(string)
- elif level == "quiet":
- pass
|