truedat101 / gitinspector

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

Terminal encoding error when running on Yosemite #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. run it from terminal
2.
3.

What is the expected output? What do you see instead?
$ python gitinspector.py ~/repos/joniab/
Statistical information for the repository 'joniab' was gathered on 2014/12/26.
The following historical commit information, by author, was found in the
repository:

Author                     Commits    Insertions      Deletions    % of changes
Niklas                           4           554             48           10.26
Niklas Osterlund                33          2256            685           50.14
Traceback (most recent call last):
  File "gitinspector.py", line 194, in <module>
    main()
  File "gitinspector.py", line 182, in main
    __run__.output()
  File "gitinspector.py", line 73, in output
    outputable.output(changes.ChangesOutput(self.hard))
  File "/Users/niklasosterlund/Dropbox/public repos/gitinspector/gitinspector/outputable.py", line 38, in output
    outputable.output_text()
  File "/Users/niklasosterlund/Dropbox/public repos/gitinspector/gitinspector/changes.py", line 289, in output_text
    print(terminal.ljust(i, 20)[0:20 - terminal.get_excess_column_count(i)], end=" ")
UnicodeEncodeError: 'ascii' codec can't encode character u'\xd6' in position 7: 
ordinal not in range(128)

What version of the product are you using? What version of Python? On what
operating system?
latest from git repository, on yosemite

Please provide any additional information below.
fixed it by adding '.encode('ascii', 'ignore')' in terminal.py, like so:
def ljust(string, pad):
    return string.ljust(pad - get_excess_column_count(string)).encode('ascii', 'ignore')

def rjust(string, pad):
    return string.rjust(pad - get_excess_column_count(string)).encode('ascii', 'ignore')

If submitting a patch, you guarantee that you are the original author of
the work or that the patch is based on code from a compatible license.

Original issue reported on code.google.com by niklas.o...@gmail.com on 26 Dec 2014 at 9:47

GoogleCodeExporter commented 9 years ago
seems to be many places to edit though, not sure if there is a smarter way?? 
see this error for example

$ python gitinspector.py -T --format='html' ~/repos/joniab/
Traceback (most recent call last):
  File "gitinspector.py", line 194, in <module>
    main()
  File "gitinspector.py", line 182, in main
    __run__.output()
  File "gitinspector.py", line 72, in output
    format.output_header()
  File "/Users/niklasosterlund/Dropbox/public repos/gitinspector/gitinspector/format.py", line 101, in output_header
    hide_minor_rows = _("Hide rows with minor work")))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 
14182: ordinal not in range(128)

Original comment by niklas.o...@gmail.com on 26 Dec 2014 at 9:53

GoogleCodeExporter commented 9 years ago
Has been reported previously.

This is because your terminal is configured to use ascii. Gitinspector will 
always try to output characters into the chosen encoding. Most likely, it's 
trying to encode unicode characters into ascii (which is your chosen encoding). 
If you make sure to set your LANG to something like en_US.UTF-8 it should start 
working. Refer to the other issue you submitted.

It would also work to introduce encode everywhere and use 
getpreferredencoding() + "ignore" on all encode calls, but this is more of a 
hassle - and would also result in skipped characters.

/Adam Waldenberg

Original comment by gitinspe...@ejwa.se on 27 Dec 2014 at 6:23

GoogleCodeExporter commented 9 years ago
Thank you, it solved it and I learned something new :)

Original comment by niklas.o...@gmail.com on 27 Dec 2014 at 9:46