Allow users to save an error report

This commit is contained in:
2018-08-14 17:15:54 +02:00
parent 1a63105d5b
commit 4fea9526b9

View File

@@ -19,7 +19,6 @@ from ..foundation import context as benchmark_context
from .global_state import G
from . import draw
QUICK_SCENES = ["bmw27",
"classroom"]
@@ -363,6 +362,9 @@ class BENCHMARK_PT_main(Panel):
text = "Retry Submission"
sub.operator("benchmark.share", text=text)
if G.submission_exception:
sub.operator("benchmark.save_error_report", text="Save Error Report...")
sub = col.row()
subsub = sub.split()
subsub.emboss = 'LINK'
@@ -374,7 +376,8 @@ class BENCHMARK_PT_main(Panel):
subsub.scale_y = 1.5
subsub.operator("benchmark.restart", text="Start Again")
split.label()
split.label('blablabla')
def draw(self, context):
with G.progress_lock:
@@ -638,6 +641,66 @@ class BENCHMARK_OT_save(bpy.types.Operator):
make_buttons_green()
class BENCHMARK_OT_save_error_report(bpy.types.Operator):
bl_idname = "benchmark.save_error_report"
bl_label = "Save Error Report"
filepath: bpy.props.StringProperty(
subtype='FILE_PATH',
options={'SKIP_SAVE'},
)
@classmethod
def poll(cls, context) -> bool:
with G.progress_lock:
return G.submission_exception is not None
def execute(self, context):
import traceback
import functools
import pprint
from benchmark.version import version
with G.progress_lock, open(self.filepath, "w", encoding='utf-8') as outfile:
p = functools.partial(print, file=outfile)
p(20 * '=', 'Benchmark Client')
p('version:', version)
if 'MYDATA' in os.environ:
p('mydata URL:', os.environ['MYDATA'])
p()
p(20 * '=', 'Exception:')
# We don't have the traceback info here any more, hence 'exception only'
ex = G.submission_exception
exc_info = traceback.format_exception_only(type(ex), ex)
for line in exc_info:
p(line)
p()
p(20 * '=', 'State:')
g_dict = {k: v for k, v in G.__dict__.items()
if not k.startswith('_')}
p(pprint.pformat(g_dict, width=120))
make_buttons_green()
return {'FINISHED'}
def invoke(self, context, event):
import os
make_buttons_default()
if not self.filepath:
self.filepath = os.path.join(
os.path.expanduser("~"), "benchmark-error-report.txt")
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
def cancel(self, context):
make_buttons_green()
class BENCHMARK_OT_share(bpy.types.Operator):
bl_idname = "benchmark.share"
bl_label = "Share Benchmark Result"
@@ -842,6 +905,7 @@ classes = (
BENCHMARK_OT_run_quick,
BENCHMARK_OT_run_complete,
BENCHMARK_OT_save,
BENCHMARK_OT_save_error_report,
BENCHMARK_OT_share,
BENCHMARK_OT_opendata_link,
)