Skip to content

Commit 846362a

Browse files
authored
Merge pull request #4334 from OpenShot/sentry_fixes
Sentry fixes
2 parents 1fae0e3 + 3e1f826 commit 846362a

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/classes/json_data.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def convert_paths_to_absolute(self, file_path, data):
253253
# Optimized regex replacement
254254
data = re.sub(path_regex, self.replace_string_to_absolute, data)
255255

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

259259
return data
260260

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

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

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

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

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

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

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

309+
# Determine windows drives that the project and file are on
310+
project_win_drive = os.path.splitdrive(path_context.get("new_project_folder", ""))[0]
311+
file_win_drive = os.path.splitdrive(path)[0]
312+
if file_win_drive != project_win_drive:
313+
log.debug("Drive mismatch, not making path relative: %s", orig_abs_path)
314+
# If the file is on different drive. Don't abbreviate the path.
315+
clean_path = orig_abs_path.replace("\\", "/")
316+
clean_path = json.dumps(clean_path, ensure_ascii=False)
317+
return f"{key}: {clean_path}"
318+
307319
# Remove file from abs path
308320
orig_abs_folder = os.path.dirname(orig_abs_path)
309321

310-
# Calculate new relateive path
322+
log.debug("Generating new relative path for %s", orig_abs_path)
311323
new_rel_path_folder = os.path.relpath(orig_abs_folder, path_context.get("new_project_folder", ""))
312324
new_rel_path = os.path.join(new_rel_path_folder, file_path).replace("\\", "/")
313325
new_rel_path = json.dumps(new_rel_path, ensure_ascii=False)
@@ -328,8 +340,8 @@ def convert_paths_to_relative(self, file_path, previous_path, data):
328340
# Optimized regex replacement
329341
data = re.sub(path_regex, self.replace_string_to_relative, data)
330342

331-
except Exception as ex:
332-
log.error("Error while converting absolute paths to relative paths: %s" % str(ex))
343+
except Exception:
344+
log.error("Error while converting absolute paths to relative paths", exc_info=1)
333345

334346
return data
335347

src/windows/models/properties_model.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ def remove_keyframe(self, item):
195195
if not c:
196196
return
197197

198-
# Create reference
198+
# Create reference
199199
clip_data = c.data
200200
if object_id:
201201
clip_data = c.data.get('objects').get(object_id)
202-
202+
203203
if property_key in clip_data: # Update clip attribute
204204
log_id = "{}/{}".format(clip_id, object_id) if object_id else clip_id
205205
log.debug("%s: remove %s keyframe. %s", log_id, property_key, clip_data.get(property_key))
@@ -281,7 +281,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
281281
c = Effect.get(id=clip_id)
282282

283283
if c:
284-
# Create reference
284+
# Create reference
285285
clip_data = c.data
286286
if object_id:
287287
clip_data = c.data.get('objects').get(object_id)
@@ -301,7 +301,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
301301
# Keyframe
302302
# Loop through points, find a matching points on this frame
303303
found_point = False
304-
for point in clip_data[property_key][color]["Points"]:
304+
for point in clip_data[property_key][color].get("Points", []):
305305
log.debug("looping points: co.X = %s" % point["co"]["X"])
306306
if interpolation == -1 and point["co"]["X"] == self.frame_number:
307307
# Found point, Update value
@@ -348,7 +348,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
348348
if not found_point:
349349
clip_updated = True
350350
log.debug("Created new point at X=%d", self.frame_number)
351-
clip_data[property_key][color]["Points"].append({
351+
clip_data[property_key][color].setdefault("Points", []).append({
352352
'co': {'X': self.frame_number, 'Y': new_value},
353353
'interpolation': 1,
354354
})
@@ -357,7 +357,7 @@ def color_update(self, item, new_color, interpolation=-1, interpolation_details=
357357
clip_data = {property_key: clip_data[property_key]}
358358
if object_id:
359359
clip_data = {'objects': {object_id: clip_data}}
360-
360+
361361
# Save changes
362362
if clip_updated:
363363
# Save
@@ -430,8 +430,8 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
430430
c = Effect.get(id=clip_id)
431431

432432
if c:
433-
434-
# Create reference
433+
434+
# Create reference
435435
clip_data = c.data
436436
if object_id:
437437
clip_data = c.data.get('objects').get(object_id)
@@ -447,7 +447,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
447447
# Loop through points, find a matching points on this frame
448448
found_point = False
449449
point_to_delete = None
450-
for point in clip_data[property_key]["Points"]:
450+
for point in clip_data[property_key].get('Points', []):
451451
log.debug("looping points: co.X = %s" % point["co"]["X"])
452452
if interpolation == -1 and point["co"]["X"] == self.frame_number:
453453
# Found point, Update value
@@ -503,7 +503,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
503503
elif not found_point and new_value is not None:
504504
clip_updated = True
505505
log.debug("Created new point at X=%d", self.frame_number)
506-
clip_data[property_key]["Points"].append({
506+
clip_data[property_key].setdefault('Points', []).append({
507507
'co': {'X': self.frame_number, 'Y': new_value},
508508
'interpolation': 1})
509509

0 commit comments

Comments
 (0)