From 4fea9526b9ea4a4676d32fbafe4592fbe2146221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 14 Aug 2018 17:15:54 +0200 Subject: [PATCH] Allow users to save an error report --- benchmark/space/__init__.py | 68 +++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/benchmark/space/__init__.py b/benchmark/space/__init__.py index 2c73e91..f7eb808 100644 --- a/benchmark/space/__init__.py +++ b/benchmark/space/__init__.py @@ -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, )