Skip to content

Commit

Permalink
Merge pull request #318 from mapillary/fix-ipc-windows-encoding
Browse files Browse the repository at this point in the history
fix: ipc encoding on Windows for import paths encoded as cp1252
  • Loading branch information
kratico authored Jan 10, 2019
2 parents 1192b29 + b9cf774 commit 4a1c6b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mapillary_tools/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from tqdm import tqdm
from . import ipc
from .error import print_error
from .utils import force_decode

STATUS_PAIRS = {"success": "failed",
"failed": "success"
Expand Down Expand Up @@ -823,9 +824,11 @@ def create_and_log_process(image, process, status, mapillary_description={}, ver
process))
os.remove(log_MAPJson)

decoded_image = force_decode(image)

ipc.send(
process,
{ 'image': image, 'status': status, 'description': mapillary_description })
{ 'image': decoded_image, 'status': status, 'description': mapillary_description })


def user_properties(user_name,
Expand Down
5 changes: 4 additions & 1 deletion mapillary_tools/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import processing
from . import ipc
from .error import print_error
from .utils import force_decode

if os.getenv("AWS_S3_ENDPOINT", None) is None:
MAPILLARY_UPLOAD_URL = "https://d22zcsn13kp53w.cloudfront.net/"
Expand Down Expand Up @@ -723,10 +724,12 @@ def create_upload_log(filepath, status):
if os.path.isfile(upload_opposite_log_filepath):
os.remove(upload_opposite_log_filepath)

decoded_filepath = force_decode(filepath)

ipc.send(
'upload',
{
'image': filepath,
'image': decoded_filepath,
'status': 'success' if status == 'upload_success' else 'failed',
})

Expand Down
8 changes: 8 additions & 0 deletions mapillary_tools/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def force_decode(string, codecs=['utf8', 'cp1252']):
for i in codecs:
try:
return string.decode(i)
except UnicodeDecodeError:
pass
print('cannot decode string: %s' % (string))
return string.decode('utf8', errors='replace')

0 comments on commit 4a1c6b6

Please sign in to comment.