dysosmus / gitinspector

Automatically exported from code.google.com/p/gitinspector
GNU General Public License v3.0
0 stars 0 forks source link

Running script on headless terminal causes exception #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run script on Jenkins, on a remote slave.
2. or run script on a remote machine using ssh without the -t option.
3. hmmm. I suspect this will happen on any headless terminal, but I may be 
wrong.

What is the expected output? What do you see instead?
python gitinspector/gitinspector.py -f html -HTlr 
/scratch/jenkins/workspace/_foo1
Traceback (most recent call last):
  File "gitinspector/gitinspector.py", line 196, in <module>
    main()
  File "gitinspector/gitinspector.py", line 107, in main
    argv = terminal.convert_command_line_to_utf8()
  File "/scratch/jenkins/workspace/_foo1/gitinspector/terminal.py", line 117, in convert_command_line_to_utf8
    argv.append(arg.decode(sys.stdin.encoding, "replace"))
TypeError: decode() argument 1 must be string, not None

Note that on headless terminals, "None" is expected for sys.stdin.encoding:
python -c 'import sys; print sys.stdin.encoding'
None

What version of the product are you using? What version of Python? On what
operating system?
Python 2.6
Using gitinspector_0.3.1.zip

> uname -a
Linux localhost 3.7.10-101.fc17.x86_64 #1 SMP Wed Feb 27 19:14:22 UTC 2013 
x86_64 x86_64 x86_64 GNU/Linux
(But I can reproduce this on any headless non-windows OS terminal.)

Please provide any additional information below.
Let me know if you want me to try anything out for you. Thanks!

Original issue reported on code.google.com by gray...@gmail.com on 9 Nov 2013 at 1:00

GoogleCodeExporter commented 9 years ago
Hi. I run gitinspector on many remote (headless systems) without a hitch. This 
just sounds to me like a misconfigured terminal? What does the following script 
return?:

import locale
import sys

print locale.getpreferredencoding()
print sys.getdefaultencoding()
print sys.stdout.encoding
print sys.stdin.encoding

Gitinspector uses unicode internally; so it needs a reference point in order to 
properly encode everything and anything into the right format.

It would be possible to just choose a default encoding when "None" is detected; 
I don't know if this is the "correct" solution, though.

Also, if you know the encoding, you could try executing something like the 
following on the terminal:

export PYTHONIOENCODING=utf-8; gitinspector.py <opts>

This forces sys.*.encoding into the encoding you specify. 

/Adam Waldenberg

Original comment by gitinspe...@ejwa.se on 9 Nov 2013 at 11:28

GoogleCodeExporter commented 9 years ago
Here is the output:
print locale.getpreferredencoding() -> UTF-8
print sys.getdefaultencoding()      -> ascii
print sys.stdout.encoding           -> None
print sys.stdin.encoding            -> None

I tried the the following:
export PYTHONIOENCODING=utf-8

And it worked like a charm!
Jenkins is happy :)

Yeah, I don't know if the terminal is mis-configured, and I agree with you that 
it may not be the best assumption to set a default encoding if "None" is 
detected.  Maybe a potential "fix" is to detect "None" and tell the user to 
export the environment variable with the correct encoding.

Thanks for the quick response! Great tool!

Original comment by gray...@gmail.com on 11 Nov 2013 at 2:27

GoogleCodeExporter commented 9 years ago
Great! Good thing that it worked.

I have been looking around a bit in order to somehow improve the behavior. A 
common solution seems to be to use the preferred encoding (if one is set). As 
you proposed, a warning on stderr is probably in order also; just to let the 
user know that something *might* be wrong with the settings of the terminal.

I'll keep this issue open until I have time to do something about it.

/Adam Waldenberg

Original comment by gitinspe...@ejwa.se on 15 Nov 2013 at 12:37

GoogleCodeExporter commented 9 years ago
I'll try to improve this before the next release.

Original comment by gitinspe...@ejwa.se on 8 Jan 2014 at 2:48

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 23bc5fbbea90.

Original comment by gitinspe...@ejwa.se on 8 Jan 2014 at 5:06