@@ -253,8 +253,8 @@ def convert_paths_to_absolute(self, file_path, data):
253
253
# Optimized regex replacement
254
254
data = re .sub (path_regex , self .replace_string_to_absolute , data )
255
255
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 )
258
258
259
259
return data
260
260
@@ -266,14 +266,16 @@ def replace_string_to_relative(self, match):
266
266
267
267
# Determine if thumbnail path is found
268
268
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 )
270
271
new_path = os .path .join ("thumbnail" , file_path ).replace ("\\ " , "/" )
271
272
new_path = json .dumps (new_path , ensure_ascii = False )
272
273
return '"%s": %s' % (key , new_path )
273
274
274
275
# Determine if @transitions path is found
275
276
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 )
277
279
folder_path , category_path = os .path .split (folder_path )
278
280
279
281
# Convert path to @transitions/ path
@@ -283,15 +285,15 @@ def replace_string_to_relative(self, match):
283
285
284
286
# Determine if @emojis path is found
285
287
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 )
288
290
new_path = os .path .join ("@emojis" , file_path ).replace ("\\ " , "/" )
289
291
new_path = json .dumps (new_path , ensure_ascii = False )
290
292
return '"%s": %s' % (key , new_path )
291
293
292
294
# Determine if @assets path is found
293
295
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 )
295
297
folder_path = folder_path .replace (path_context ["new_project_assets" ], "@assets" )
296
298
297
299
# Convert path to @assets/ path
@@ -304,10 +306,20 @@ def replace_string_to_relative(self, match):
304
306
# Convert path to the correct relative path (based on the existing folder)
305
307
orig_abs_path = os .path .abspath (path )
306
308
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
+
307
319
# Remove file from abs path
308
320
orig_abs_folder = os .path .dirname (orig_abs_path )
309
321
310
- # Calculate new relateive path
322
+ log . debug ( "Generating new relative path for %s" , orig_abs_path )
311
323
new_rel_path_folder = os .path .relpath (orig_abs_folder , path_context .get ("new_project_folder" , "" ))
312
324
new_rel_path = os .path .join (new_rel_path_folder , file_path ).replace ("\\ " , "/" )
313
325
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):
328
340
# Optimized regex replacement
329
341
data = re .sub (path_regex , self .replace_string_to_relative , data )
330
342
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 )
333
345
334
346
return data
335
347
0 commit comments