28
28
"""
29
29
30
30
import os
31
- import platform
32
31
import shutil
33
32
import sys
34
33
import webbrowser
50
49
QLineEdit , QSlider , QLabel , QComboBox , QTextEdit
51
50
)
52
51
53
- from classes import info , ui_util , settings , qt_types , updates
52
+ from classes import exceptions , info , settings , qt_types , ui_util , updates
54
53
from classes .app import get_app
55
54
from classes .conversion import zoomToSeconds , secondsToZoom
56
55
from classes .exporters .edl import export_edl
57
56
from classes .exporters .final_cut_pro import export_xml
58
57
from classes .importers .edl import import_edl
59
58
from classes .importers .final_cut_pro import import_xml
60
59
from classes .logger import log
61
- from classes .metrics import (
62
- track_metric_session , track_metric_screen ,
63
- track_metric_error , track_exception_stacktrace ,
64
- )
60
+ from classes .metrics import track_metric_session , track_metric_screen
65
61
from classes .query import Clip , Transition , Marker , Track
66
62
from classes .thumbnail import httpThumbnailServerThread
67
63
from classes .time_parts import secondsToTimecode
@@ -217,101 +213,26 @@ def recover_backup(self):
217
213
def create_lock_file (self ):
218
214
"""Create a lock file"""
219
215
lock_path = os .path .join (info .USER_PATH , ".lock" )
220
- lock_value = str (uuid4 ())
221
-
222
216
# Check if it already exists
223
217
if os .path .exists (lock_path ):
224
- # Walk the libopenshot log (if found), and try and find last line before this launch
225
- log_path = os .path .join (info .USER_PATH , "libopenshot.log" )
226
- last_log_line = ""
227
- last_stack_trace = ""
228
- found_stack = False
229
- log_start_counter = 0
230
- if os .path .exists (log_path ):
231
- with open (log_path , "rb" ) as f :
232
- # Read from bottom up
233
- for raw_line in reversed (self .tail_file (f , 500 )):
234
- line = str (raw_line , 'utf-8' )
235
- # Detect stack trace
236
- if "End of Stack Trace" in line :
237
- found_stack = True
238
- continue
239
- if "Unhandled Exception: Stack Trace" in line :
240
- found_stack = False
241
- continue
242
- if "libopenshot logging:" in line :
243
- log_start_counter += 1
244
- if log_start_counter > 1 :
245
- # Found the previous log start, too old now
246
- break
247
-
248
- if found_stack :
249
- # Append line to beginning of stacktrace
250
- last_stack_trace = line + last_stack_trace
251
-
252
- # Ignore certain useless lines
253
- line .strip ()
254
- if all (["---" not in line ,
255
- "libopenshot logging:" not in line ,
256
- not last_log_line ,
257
- ]):
258
- last_log_line = line
259
-
260
- # Split last stack trace (if any)
261
- if last_stack_trace :
262
- # Get top line of stack trace (for metrics)
263
- last_log_line = last_stack_trace .split ("\n " )[0 ].strip ()
264
-
265
- # Send stacktrace for debugging (if send metrics is enabled)
266
- track_exception_stacktrace (last_stack_trace , "libopenshot" )
267
-
268
- # Clear / normalize log line (so we can roll them up in the analytics)
269
- if last_log_line :
270
- # Format last log line based on OS (since each OS can be formatted differently)
271
- if platform .system () == "Darwin" :
272
- last_log_line = "mac-%s" % last_log_line [58 :].strip ()
273
- elif platform .system () == "Windows" :
274
- last_log_line = "windows-%s" % last_log_line
275
- elif platform .system () == "Linux" :
276
- last_log_line = "linux-%s" % last_log_line .replace ("/usr/local/lib/" , "" )
277
-
278
- # Remove '()' from line, and split. Trying to grab the beginning of the log line.
279
- last_log_line = last_log_line .replace ("()" , "" )
280
- log_parts = last_log_line .split ("(" )
281
- if len (log_parts ) == 2 :
282
- last_log_line = "-%s" % log_parts [0 ].replace (
283
- "logger_libopenshot:INFO " , "" ).strip ()[:64 ]
284
- elif len (log_parts ) >= 3 :
285
- last_log_line = "-%s (%s" % (log_parts [0 ].replace (
286
- "logger_libopenshot:INFO " , "" ).strip ()[:64 ], log_parts [1 ])
287
- else :
288
- last_log_line = ""
289
-
290
- # Throw exception (with last libopenshot line... if found)
291
- log .error (
292
- "Unhandled crash detected... will attempt to recover backup project: %s"
293
- % info .BACKUP_FILE )
294
- track_metric_error ("unhandled-crash%s" % last_log_line , True )
295
-
296
- # Remove file
218
+ exceptions .libopenshot_crash_recovery ()
219
+ log .error ("Unhandled crash detected. Preserving cache." )
297
220
self .destroy_lock_file ()
298
-
299
221
else :
300
222
# Normal startup, clear thumbnails
301
223
self .clear_all_thumbnails ()
302
224
303
225
# Write lock file (try a few times if failure)
226
+ lock_value = str (uuid4 ())
304
227
for attempt in range (5 ):
305
228
try :
306
229
# Create lock file
307
230
with open (lock_path , 'w' ) as f :
308
231
f .write (lock_value )
309
- log .debug ("Wrote value {} to lock file {}" .format (
310
- lock_value , lock_path ))
232
+ log .debug ("Wrote value %s to lock file %s" , lock_value , lock_path )
311
233
break
312
234
except OSError :
313
- log .debug ('Failed to write lock file (attempt: {})' .format (
314
- attempt ), exc_info = 1 )
235
+ log .debug ("Failed to write lock file (attempt: %d)" , attempt , exc_info = 1 )
315
236
sleep (0.25 )
316
237
317
238
def destroy_lock_file (self ):
@@ -330,25 +251,6 @@ def destroy_lock_file(self):
330
251
log .debug ('Failed to destroy lock file (attempt: %s)' % attempt , exc_info = 1 )
331
252
sleep (0.25 )
332
253
333
- def tail_file (self , f , n , offset = None ):
334
- """Read the end of a file (n number of lines)"""
335
- avg_line_length = 90
336
- to_read = n + (offset or 0 )
337
-
338
- while True :
339
- try :
340
- # Seek to byte position
341
- f .seek (- (avg_line_length * to_read ), 2 )
342
- except IOError :
343
- # Byte position not found
344
- f .seek (0 )
345
- pos = f .tell ()
346
- lines = f .read ().splitlines ()
347
- if len (lines ) >= to_read or pos == 0 :
348
- # Return the lines
349
- return lines [- to_read :offset and - offset or None ]
350
- avg_line_length *= 2
351
-
352
254
def actionNew_trigger (self ):
353
255
354
256
app = get_app ()
0 commit comments