- added the mechanism to create an error log in the data path where to write debug data for the crashes of FlatCAM

This commit is contained in:
Marius Stanciu
2020-11-28 15:51:37 +02:00
committed by Marius
parent 0ede053fe1
commit 16ae703a61
3 changed files with 85 additions and 20 deletions

View File

@@ -10,6 +10,7 @@ CHANGELOG for FlatCAM beta
28.11.2020 28.11.2020
- updated the Italian translation (by Massimiliano Golfetto) - updated the Italian translation (by Massimiliano Golfetto)
- added the mechanism to create an error log in the data path where to write debug data for the crashes of FlatCAM
27.11.2020 27.11.2020

View File

@@ -1,5 +1,7 @@
import sys import sys
import os import os
import traceback
from datetime import datetime
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtCore import QSettings, Qt from PyQt5.QtCore import QSettings, Qt
@@ -12,10 +14,10 @@ from multiprocessing import freeze_support
if sys.platform == "win32": if sys.platform == "win32":
# cx_freeze 'module win32' workaround # cx_freeze 'module win32' workaround
pass from win32comext.shell import shell, shellcon
MIN_VERSION_MAJOR = 3 MIN_VERSION_MAJOR = 3
MIN_VERSION_MINOR = 5 MIN_VERSION_MINOR = 6
def debug_trace(): def debug_trace():
@@ -35,24 +37,68 @@ if __name__ == '__main__':
# NOTE: Never talk to the GUI from threads! This is why I commented the above. # NOTE: Never talk to the GUI from threads! This is why I commented the above.
freeze_support() freeze_support()
portable = False
# Folder for user settings.
if sys.platform == 'win32':
# #######################################################################################################
# ####### CONFIG FILE WITH PARAMETERS REGARDING PORTABILITY #############################################
# #######################################################################################################
config_file = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '\\config\\configuration.txt'
try:
with open(config_file, 'r'):
pass
except FileNotFoundError:
config_file = os.path.dirname(os.path.realpath(__file__)) + '\\config\\configuration.txt'
with open(config_file, 'r') as f:
for line in f:
param = str(line).replace('\n', '').rpartition('=')
if param[0] == 'portable':
try:
portable = eval(param[2])
except NameError:
portable = False
if portable is False:
data_path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, None, 0) + '\\FlatCAM'
else:
data_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '\\config'
else:
data_path = os.path.expanduser('~') + '/.FlatCAM'
if not os.path.exists(data_path):
os.makedirs(data_path)
log_file_path = os.path.join(data_path, "log.txt")
major_v = sys.version_info.major major_v = sys.version_info.major
minor_v = sys.version_info.minor minor_v = sys.version_info.minor
# Supported Python version is >= 3.5
if major_v >= MIN_VERSION_MAJOR:
if minor_v >= MIN_VERSION_MINOR:
pass
else:
print("FlatCAM BETA uses PYTHON 3 or later. The version minimum is %s.%s\n"
"Your Python version is: %s.%s" % (MIN_VERSION_MAJOR, MIN_VERSION_MINOR, str(major_v), str(minor_v)))
if minor_v >= 8: v_msg = "FlatCAM Evo uses PYTHON 3 or later. The version minimum is %s.%s\n"\
os._exit(0) "Your Python version is: %s.%s" % (MIN_VERSION_MAJOR, MIN_VERSION_MINOR, str(major_v), str(minor_v))
else:
sys.exit(0) # Supported Python version is >= 3.6
else: if major_v < MIN_VERSION_MAJOR or (major_v >= MIN_VERSION_MAJOR and minor_v < MIN_VERSION_MINOR):
print("FlatCAM BETA uses PYTHON 3 or later. The version minimum is %s.%s\n" print(v_msg)
"Your Python version is: %s.%s" % (MIN_VERSION_MAJOR, MIN_VERSION_MINOR, str(major_v), str(minor_v))) msg = '%s\n' % str(datetime.today())
sys.exit(0) msg += v_msg
try:
with open(log_file_path) as f:
log_file = f.read()
log_file += '\n' + msg
with open(log_file_path, 'w') as f:
f.write(log_file)
except IOError:
with open(log_file_path, 'w') as f:
f.write(msg)
if minor_v >= 8:
os._exit(0)
else:
sys.exit(0)
debug_trace() debug_trace()
VisPyPatches.apply_patches() VisPyPatches.apply_patches()
@@ -82,6 +128,26 @@ if __name__ == '__main__':
else: else:
QtWidgets.QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, False) QtWidgets.QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, False)
def excepthook(exc_type, exc_value, exc_tb):
msg = '%s\n' % str(datetime.today())
msg += "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
try:
with open(log_file_path) as f:
log_file = f.read()
log_file += '\n' + msg
with open(log_file_path, 'w') as f:
f.write(log_file)
except IOError:
with open(log_file_path, 'w') as f:
f.write(msg)
QtWidgets.QApplication.quit()
# or QtWidgets.QApplication.exit(0)
sys.excepthook = excepthook
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
app.setAttribute(Qt.AA_UseHighDpiPixmaps) app.setAttribute(Qt.AA_UseHighDpiPixmaps)
@@ -92,5 +158,6 @@ if __name__ == '__main__':
app.setStyle(style) app.setStyle(style)
fc = App(qapp=app) fc = App(qapp=app)
sys.exit(app.exec_()) sys.exit(app.exec_())
# app.exec_() # app.exec_()

View File

@@ -508,9 +508,6 @@ class App(QtCore.QObject):
os.makedirs(self.data_path) os.makedirs(self.data_path)
self.log.debug('Created data folder: ' + self.data_path) self.log.debug('Created data folder: ' + self.data_path)
os.makedirs(os.path.join(self.data_path, 'preprocessors'))
self.log.debug('Created data preprocessors folder: ' + os.path.join(self.data_path, 'preprocessors'))
self.preprocessorpaths = self.preprocessors_path() self.preprocessorpaths = self.preprocessors_path()
if not os.path.exists(self.preprocessorpaths): if not os.path.exists(self.preprocessorpaths):
os.makedirs(self.preprocessorpaths) os.makedirs(self.preprocessorpaths)