UTF-8 file paths error on python 2
Python 2 needs UTF-8 decode since it uses 'ascii' decode by default. Python 3 might have problems converting back to UTF-8 in case of Unicode surrogates Signed-off-by: Josenivaldo Benito Jr <jrbenito@benito.qsl.br>
This commit is contained in:
parent
137c32262b
commit
122d76d061
15
bin/solaar
15
bin/solaar
|
@ -26,7 +26,20 @@ def init_paths():
|
||||||
import sys
|
import sys
|
||||||
import os.path as _path
|
import os.path as _path
|
||||||
|
|
||||||
prefix = _path.normpath(_path.join(_path.realpath(sys.path[0]), '..'))
|
# Python 2 need conversion from utf-8 filenames
|
||||||
|
# Python 3 might have problems converting back to UTF-8 in case of Unicode surrogates
|
||||||
|
try:
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
decoded_path = sys.path[0].decode(sys.getfilesystemencoding())
|
||||||
|
else:
|
||||||
|
decoded_path = sys.path[0]
|
||||||
|
sys.path[0].encode(sys.getfilesystemencoding())
|
||||||
|
|
||||||
|
except UnicodeError:
|
||||||
|
sys.stderr.write('ERROR: Solaar cannot recognize encoding of filesystem path, this may happen because non UTF-8 characters in the pathname.\n')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
prefix = _path.normpath(_path.join(_path.realpath(decoded_path), '..'))
|
||||||
src_lib = _path.join(prefix, 'lib')
|
src_lib = _path.join(prefix, 'lib')
|
||||||
share_lib = _path.join(prefix, 'share', 'solaar', 'lib')
|
share_lib = _path.join(prefix, 'share', 'solaar', 'lib')
|
||||||
for location in src_lib, share_lib:
|
for location in src_lib, share_lib:
|
||||||
|
|
Loading…
Reference in New Issue