Skip to content

Commit

Permalink
Merge pull request #4334 from OpenShot/sentry_fixes
Browse files Browse the repository at this point in the history
Sentry fixes
  • Loading branch information
jonoomph authored Aug 21, 2021
2 parents 1fae0e3 + 3e1f826 commit 846362a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
32 changes: 22 additions & 10 deletions src/classes/json_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def convert_paths_to_absolute(self, file_path, data):
# Optimized regex replacement
data = re.sub(path_regex, self.replace_string_to_absolute, data)

except Exception as ex:
log.error("Error while converting relative paths to absolute paths: %s" % str(ex))
except Exception:
log.error("Error while converting relative paths to absolute paths", exc_info=1)

return data

Expand All @@ -266,14 +266,16 @@ def replace_string_to_relative(self, match):

# Determine if thumbnail path is found
if info.THUMBNAIL_PATH in folder_path:
# Convert path to relative thumbnail path
log.debug("Generating relative thumbnail path to %s in %s",
file_path, folder_path)
new_path = os.path.join("thumbnail", file_path).replace("\\", "/")
new_path = json.dumps(new_path, ensure_ascii=False)
return '"%s": %s' % (key, new_path)

# Determine if @transitions path is found
elif os.path.join(info.PATH, "transitions") in folder_path:
# Yes, this is an OpenShot transition
log.debug("Generating relative @transitions path for %s in %s",
file_path, folder_path)
folder_path, category_path = os.path.split(folder_path)

# Convert path to @transitions/ path
Expand All @@ -283,15 +285,15 @@ def replace_string_to_relative(self, match):

# Determine if @emojis path is found
elif os.path.join(info.PATH, "emojis") in folder_path:
# Yes, this is an OpenShot emoji
# Convert path to @emojis/ path
log.debug("Generating relative @emojis path for %s in %s",
file_path, folder_path)
new_path = os.path.join("@emojis", file_path).replace("\\", "/")
new_path = json.dumps(new_path, ensure_ascii=False)
return '"%s": %s' % (key, new_path)

# Determine if @assets path is found
elif path_context["new_project_assets"] in folder_path:
# Yes, this is an OpenShot transitions
log.debug("Replacing path to %s in %s", file_path, folder_path)
folder_path = folder_path.replace(path_context["new_project_assets"], "@assets")

# Convert path to @assets/ path
Expand All @@ -304,10 +306,20 @@ def replace_string_to_relative(self, match):
# Convert path to the correct relative path (based on the existing folder)
orig_abs_path = os.path.abspath(path)

# Determine windows drives that the project and file are on
project_win_drive = os.path.splitdrive(path_context.get("new_project_folder", ""))[0]
file_win_drive = os.path.splitdrive(path)[0]
if file_win_drive != project_win_drive:
log.debug("Drive mismatch, not making path relative: %s", orig_abs_path)
# If the file is on different drive. Don't abbreviate the path.
clean_path = orig_abs_path.replace("\\", "/")
clean_path = json.dumps(clean_path, ensure_ascii=False)
return f"{key}: {clean_path}"

# Remove file from abs path
orig_abs_folder = os.path.dirname(orig_abs_path)

# Calculate new relateive path
log.debug("Generating new relative path for %s", orig_abs_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, ensure_ascii=False)
Expand All @@ -328,8 +340,8 @@ def convert_paths_to_relative(self, file_path, previous_path, data):
# Optimized regex replacement
data = re.sub(path_regex, self.replace_string_to_relative, data)

except Exception as ex:
log.error("Error while converting absolute paths to relative paths: %s" % str(ex))
except Exception:
log.error("Error while converting absolute paths to relative paths", exc_info=1)

return data

Expand Down
20 changes: 10 additions & 10 deletions src/windows/models/properties_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ def remove_keyframe(self, item):
if not c:
return

# Create reference
# Create reference
clip_data = c.data
if object_id:
clip_data = c.data.get('objects').get(object_id)

if property_key in clip_data: # Update clip attribute
log_id = "{}/{}".format(clip_id, object_id) if object_id else clip_id
log.debug("%s: remove %s keyframe. %s", log_id, property_key, clip_data.get(property_key))
Expand Down Expand Up @@ -281,7 +281,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
c = Effect.get(id=clip_id)

if c:
# Create reference
# Create reference
clip_data = c.data
if object_id:
clip_data = c.data.get('objects').get(object_id)
Expand All @@ -301,7 +301,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
# Keyframe
# Loop through points, find a matching points on this frame
found_point = False
for point in clip_data[property_key][color]["Points"]:
for point in clip_data[property_key][color].get("Points", []):
log.debug("looping points: co.X = %s" % point["co"]["X"])
if interpolation == -1 and point["co"]["X"] == self.frame_number:
# Found point, Update value
Expand Down Expand Up @@ -348,7 +348,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
if not found_point:
clip_updated = True
log.debug("Created new point at X=%d", self.frame_number)
clip_data[property_key][color]["Points"].append({
clip_data[property_key][color].setdefault("Points", []).append({
'co': {'X': self.frame_number, 'Y': new_value},
'interpolation': 1,
})
Expand All @@ -357,7 +357,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
clip_data = {property_key: clip_data[property_key]}
if object_id:
clip_data = {'objects': {object_id: clip_data}}

# Save changes
if clip_updated:
# Save
Expand Down Expand Up @@ -430,8 +430,8 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
c = Effect.get(id=clip_id)

if c:
# Create reference

# Create reference
clip_data = c.data
if object_id:
clip_data = c.data.get('objects').get(object_id)
Expand All @@ -447,7 +447,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
# Loop through points, find a matching points on this frame
found_point = False
point_to_delete = None
for point in clip_data[property_key]["Points"]:
for point in clip_data[property_key].get('Points', []):
log.debug("looping points: co.X = %s" % point["co"]["X"])
if interpolation == -1 and point["co"]["X"] == self.frame_number:
# Found point, Update value
Expand Down Expand Up @@ -503,7 +503,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
elif not found_point and new_value is not None:
clip_updated = True
log.debug("Created new point at X=%d", self.frame_number)
clip_data[property_key]["Points"].append({
clip_data[property_key].setdefault('Points', []).append({
'co': {'X': self.frame_number, 'Y': new_value},
'interpolation': 1})

Expand Down

0 comments on commit 846362a

Please sign in to comment.