Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Unicode path for projects work again #3229

Merged
merged 2 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/classes/json_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ def merge_settings(self, default, user):
def read_from_file(self, file_path, path_mode="ignore"):
""" Load JSON settings from a file """
try:
with open(file_path, 'r') as f:
with open(file_path, 'r', encoding='utf-8') as f:
contents = f.read()
if contents:
if path_mode == "absolute":
# Convert any paths to absolute
contents = self.convert_paths_to_absolute(file_path, contents)
return json.loads(contents, strict=False)
return json.loads(contents)
except Exception as ex:
msg = ("Couldn't load {} file: {}".format(self.data_type, ex))
log.error(msg)
Expand All @@ -145,11 +145,11 @@ def read_from_file(self, file_path, path_mode="ignore"):
def write_to_file(self, file_path, data, path_mode="ignore", previous_path=None):
""" Save JSON settings to a file """
try:
contents = json.dumps(data, indent=1)
contents = json.dumps(data, ensure_ascii=False, indent=1)
if path_mode == "relative":
# Convert any paths to relative
contents = self.convert_paths_to_relative(file_path, previous_path, contents)
with open(file_path, 'w') as f:
with open(file_path, 'w', encoding='utf-8') as f:
f.write(contents)
except Exception as ex:
msg = ("Couldn't save {} file:\n{}\n{}".format(self.data_type, file_path, ex))
Expand All @@ -164,18 +164,18 @@ def replace_string_to_absolute(self, match):
# Find absolute path of file (if needed)
if "@transitions" in path:
new_path = path.replace("@transitions", os.path.join(info.PATH, "transitions"))
new_path = json.dumps(new_path) # Escape backslashes
new_path = json.dumps(new_path, ensure_ascii=False)
return '"%s": %s' % (key, new_path)

elif "@assets" in path:
new_path = path.replace("@assets", path_context["new_project_assets"])
new_path = json.dumps(new_path) # Escape backslashes
new_path = json.dumps(new_path, ensure_ascii=False)
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", ""), path))
new_path = json.dumps(new_path) # Escape backslashes
new_path = json.dumps(new_path, ensure_ascii=False)
return '"%s": %s' % (key, new_path)

def convert_paths_to_absolute(self, file_path, data):
Expand Down Expand Up @@ -205,7 +205,7 @@ def replace_string_to_relative(self, match):
if info.THUMBNAIL_PATH in folder_path:
# Convert path to relative thumbnail path
new_path = os.path.join("thumbnail", file_path).replace("\\", "/")
new_path = json.dumps(new_path) # Escape backslashes
new_path = json.dumps(new_path, ensure_ascii=False)
return '"%s": %s' % (key, new_path)

# Determine if @transitions path is found
Expand All @@ -215,7 +215,7 @@ def replace_string_to_relative(self, match):

# Convert path to @transitions/ path
new_path = os.path.join("@transitions", category_path, file_path).replace("\\", "/")
new_path = json.dumps(new_path) # Escape backslashes
new_path = json.dumps(new_path, ensure_ascii=False)
return '"%s": %s' % (key, new_path)

# Determine if @assets path is found
Expand All @@ -225,7 +225,7 @@ def replace_string_to_relative(self, match):

# Convert path to @transitions/ path
new_path = os.path.join(folder_path, file_path).replace("\\", "/")
new_path = json.dumps(new_path) # Escape backslashes
new_path = json.dumps(new_path, ensure_ascii=False)
return '"%s": %s' % (key, new_path)

# Find absolute path of file (if needed)
Expand All @@ -239,7 +239,7 @@ def replace_string_to_relative(self, match):
# Calculate new relateive path
new_rel_path_folder = os.path.relpath(orig_abs_folder, path_context.get("new_project_folder", ""))
new_rel_path = os.path.join(new_rel_path_folder, file_path).replace("\\", "/")
new_rel_path = json.dumps(new_rel_path) # Escape backslashes
new_rel_path = json.dumps(new_rel_path, ensure_ascii=False)
return '"%s": %s' % (key, new_rel_path)

def convert_paths_to_relative(self, file_path, previous_path, data):
Expand Down
2 changes: 1 addition & 1 deletion src/classes/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def do_GET(self):
if not only_path:
self.send_header('Content-type', 'image/png')
else:
self.send_header('Content-type', 'text/html')
self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers()

# Locate thumbnail
Expand Down