Files
picard/tagger.py.in

47 lines
1.5 KiB
Python

#!/usr/bin/env python3
import os
import sys
sys.path.insert(0, '.')
# This is needed to find resources when using pyinstaller
if getattr(sys, 'frozen', False):
basedir = getattr(sys, '_MEIPASS', '')
else:
basedir = os.path.dirname(os.path.abspath(__file__))
if sys.platform == 'win32':
os.environ['PATH'] = basedir + ';' + os.environ['PATH']
try:
from picard.tagger import main
main(os.path.join(basedir, 'locale'), %(autoupdate)s)
except SystemExit:
raise # Just continue with a normal application exit
except: # noqa: F722
# First try to get traceback information and write it to a log file
# with minimum chance to fail.
import tempfile
import traceback
trace = traceback.format_exc()
try:
(fd, logfile) = tempfile.mkstemp(".log", "picard-crash-")
os.write(fd, trace.encode(errors="replace"))
os.close(fd)
except: # noqa: F722
print("Failed writing log file {0}".format(logfile), file=sys.stderr)
logfile = None
# Display the crash information to the user as a dialog. This requires#
# importing Qt5 and has some potential to fail if things are broken.
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
msg = []
if logfile:
msg.append("A logfile has been written to {0}".format(logfile))
msg.append("Error details: \n{0}".format(trace))
QtWidgets.QMessageBox.critical(None, "Picard terminated unexpectedly", "\n\n".join(msg))
raise