mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-12-22 21:52:15 +01:00
Print a warning when the terminal encoding is not set (Fixes issue 19).
This fix also sets the stdin encoding to UTF-8 whenever it is not set. The behavior as the same as the one for stdout.
This commit is contained in:
parent
bc00f9731b
commit
23bc5fbbea
2 changed files with 13 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/python
|
||||
# coding: utf-8
|
||||
#
|
||||
# Copyright © 2012-2013 Ejwa Software. All rights reserved.
|
||||
# Copyright © 2012-2014 Ejwa Software. All rights reserved.
|
||||
#
|
||||
# This file is part of gitinspector.
|
||||
#
|
||||
|
@ -113,6 +113,8 @@ def __check_python_version__():
|
|||
sys.exit(_("gitinspector requires at least Python 2.6 to run (version {0} was found).").format(python_version))
|
||||
|
||||
def main():
|
||||
terminal.check_terminal_encoding()
|
||||
terminal.set_stdin_encoding()
|
||||
argv = terminal.convert_command_line_to_utf8()
|
||||
__run__ = Runner()
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# coding: utf-8
|
||||
#
|
||||
# Copyright © 2012-2013 Ejwa Software. All rights reserved.
|
||||
# Copyright © 2012-2014 Ejwa Software. All rights reserved.
|
||||
#
|
||||
# This file is part of gitinspector.
|
||||
#
|
||||
|
@ -109,6 +109,10 @@ def set_stdout_encoding():
|
|||
if not sys.stdout.isatty() and sys.version_info < (3,):
|
||||
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
|
||||
|
||||
def set_stdin_encoding():
|
||||
if not sys.stdin.isatty() and sys.version_info < (3,):
|
||||
sys.stdin = codecs.getreader("utf-8")(sys.stdin)
|
||||
|
||||
def convert_command_line_to_utf8():
|
||||
try:
|
||||
argv = []
|
||||
|
@ -119,3 +123,8 @@ def convert_command_line_to_utf8():
|
|||
return argv
|
||||
except AttributeError:
|
||||
return sys.argv
|
||||
|
||||
def check_terminal_encoding():
|
||||
if sys.stdout.isatty() and (sys.stdout.encoding == None or sys.stdin.encoding == None):
|
||||
print(_("WARNING: The terminal encoding is not correctly configured. gitinspector might malfunction. "
|
||||
"The encoding can be configured with the environment variable 'PYTHONIOENCODING'."), file=sys.stderr)
|
||||
|
|
Loading…
Reference in a new issue