Skip to content

Commit

Permalink
json_data: Eliminate utf_path
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Nov 20, 2019
1 parent ad1df9e commit 5d459d9
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/classes/json_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from classes import info

# Compiled path regex
path_regex = re.compile(r'\"(image|path)\":.*?\"(.*?)\"', re.UNICODE)
path_regex = re.compile(r'\"(image|path)\":.*?\"(.*?)\"')
path_context = {}


Expand Down Expand Up @@ -162,20 +162,19 @@ def replace_string_to_absolute(self, match):
path = match.groups(0)[1]

# Find absolute path of file (if needed)
utf_path = os.fsencode(path) # parse bytestring into unicode string
if "@transitions" in utf_path:
if "@transitions" in path:
new_path = path.replace("@transitions", os.path.join(info.PATH, "transitions"))
new_path = json.dumps(new_path) # Escape backslashes
return '"%s": %s' % (key, new_path)

elif "@assets" in utf_path:
elif "@assets" in path:
new_path = path.replace("@assets", path_context["new_project_assets"])
new_path = json.dumps(new_path) # Escape backslashes
return '"%s": %s' % (key, new_path)

else:
# Convert path to the correct relative path
new_path = os.path.abspath(os.path.join(path_context.get("new_project_folder", ""), utf_path))
new_path = os.path.abspath(os.path.join(path_context.get("new_project_folder", ""), path))
new_path = json.dumps(new_path) # Escape backslashes
return '"%s": %s' % (key, new_path)

Expand All @@ -200,8 +199,7 @@ def replace_string_to_relative(self, match):
"""Replace matched string for converting paths to relative paths"""
key = match.groups(0)[0]
path = match.groups(0)[1]
utf_path = os.fsencode(path) # parse bytestring into unicode string
folder_path, file_path = os.path.split(os.path.abspath(utf_path))
folder_path, file_path = os.path.split(os.path.abspath(path))

# Determine if thumbnail path is found
if info.THUMBNAIL_PATH in folder_path:
Expand Down Expand Up @@ -233,7 +231,7 @@ def replace_string_to_relative(self, match):
# Find absolute path of file (if needed)
else:
# Convert path to the correct relative path (based on the existing folder)
orig_abs_path = os.path.abspath(utf_path)
orig_abs_path = os.path.abspath(path)

# Remove file from abs path
orig_abs_folder = os.path.split(orig_abs_path)[0]
Expand Down

0 comments on commit 5d459d9

Please sign in to comment.