encode filenames as bytes to handle all locale setups

This was failing on environments that did not have any LANG or LC_* locale
variables set.  This is a valid setup, and is common in headless setups, so
it needs to be handled.

This also adds a new pass of the test suite without the locale env vars set
so that this situation is also tests on gitlab-ci, not only gpjenkins.

The error this caused was:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 6-18: ordinal not in range(128)
This commit is contained in:
Hans-Christoph Steiner 2017-04-03 20:24:00 +02:00
parent 4d50ab9bad
commit e58ad330f4
4 changed files with 31 additions and 26 deletions

View file

@ -1700,7 +1700,8 @@ class KnownApks:
def get_file_extension(filename):
"""get the normalized file extension, can be blank string but never None"""
if isinstance(filename, bytes):
filename = filename.decode('utf-8')
return os.path.splitext(filename)[1].lower()[1:]
@ -2333,15 +2334,17 @@ def get_per_app_repos():
def is_repo_file(filename):
'''Whether the file in a repo is a build product to be delivered to users'''
if isinstance(filename, str):
filename = filename.encode('utf-8', errors="surrogateescape")
return os.path.isfile(filename) \
and not filename.endswith('.asc') \
and not filename.endswith('.sig') \
and not filename.endswith(b'.asc') \
and not filename.endswith(b'.sig') \
and os.path.basename(filename) not in [
'index.jar',
'index_unsigned.jar',
'index.xml',
'index.html',
'index-v1.jar',
'index-v1.json',
'categories.txt',
b'index.jar',
b'index_unsigned.jar',
b'index.xml',
b'index.html',
b'index-v1.jar',
b'index-v1.json',
b'categories.txt',
]