Linux binary install script: Fix error on linux systems where the system python has an encoding of None set on stdout. Assume encoding is utf-8 in this case.

This commit is contained in:
Kovid Goyal 2014-03-07 21:49:51 +05:30
parent 0dc884efc5
commit 290462909f

View File

@ -16,7 +16,7 @@ url = 'http://status.calibre-ebook.com/dist/linux'+('64' if is64bit else '32')
signature_url = 'http://calibre-ebook.com/downloads/signatures/%s.sha512' signature_url = 'http://calibre-ebook.com/downloads/signatures/%s.sha512'
url = os.environ.get('CALIBRE_INSTALLER_LOCAL_URL', url) url = os.environ.get('CALIBRE_INSTALLER_LOCAL_URL', url)
py3 = sys.version_info[0] > 2 py3 = sys.version_info[0] > 2
enc = getattr(sys.stdout, 'encoding', 'UTF-8') enc = getattr(sys.stdout, 'encoding', 'UTF-8') or 'utf-8'
calibre_version = signature = None calibre_version = signature = None
urllib = __import__('urllib.request' if py3 else 'urllib', fromlist=1) urllib = __import__('urllib.request' if py3 else 'urllib', fromlist=1)
if py3: if py3:
@ -197,7 +197,7 @@ class ProgressBar:
def prints(*args, **kwargs): # {{{ def prints(*args, **kwargs): # {{{
f = kwargs.get('file', sys.stdout.buffer if py3 else sys.stdout) f = kwargs.get('file', sys.stdout.buffer if py3 else sys.stdout)
end = kwargs.get('end', b'\n') end = kwargs.get('end', b'\n')
enc = getattr(f, 'encoding', 'utf-8') enc = getattr(f, 'encoding', 'utf-8') or 'utf-8'
if isinstance(end, unicode): if isinstance(end, unicode):
end = end.encode(enc) end = end.encode(enc)