From aaecc86a44426846398b2b778449e9fc0aade8f8 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Wed, 28 Nov 2018 00:17:46 -0800 Subject: [PATCH] Added Bug Report button to Admin -> General. --- CHANGELOG.md | 1 + src/pug/templates/admin-general-view.pug | 5 +-- src/py/bbctrl/Web.py | 41 ++++++++++++++++++++++++ src/stylus/style.styl | 3 ++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c74a3e..78de09c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Buildbotics CNC Controller Firmware Changelog - Handle zero length dwell correctly. - Fixed problem with cached GCode file upload when file changed on disk. - Run simulation at low process priority. + - Added ``Bug Report`` button to ``Admin`` -> ``General``. ## v0.4.1 - Fix toolpath view axes bug. diff --git a/src/pug/templates/admin-general-view.pug b/src/pug/templates/admin-general-view.pug index cb09937..37040dc 100644 --- a/src/pug/templates/admin-general-view.pug +++ b/src/pug/templates/admin-general-view.pug @@ -49,8 +49,7 @@ script#admin-general-view-template(type="text/x-template") h3(slot="header") Success p(slot="body") Configuration restored. - button.pure-button.pure-button-primary(@click="confirmReset = true") - | Reset + button.pure-button.pure-button-primary(@click="confirmReset = true") Reset message(:show.sync="confirmReset") h3(slot="header") Reset to default configuration? p(slot="body") All configuration changes will be lost. @@ -65,3 +64,5 @@ script#admin-general-view-template(type="text/x-template") h2 Debugging a(href="/api/log", target="_blank") button.pure-button.pure-button-primary View Log + a(href="/api/bugreport") + button.pure-button.pure-button-primary Bug Report diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index 0e2f0f1..92d664b 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -103,6 +103,46 @@ class LogHandler(tornado.web.RequestHandler): self.set_header('Content-Type', 'text/plain') +class BugReportHandler(tornado.web.RequestHandler): + def __init__(self, app, request, **kwargs): + super(BugReportHandler, self).__init__(app, request, **kwargs) + self.app = app + + + def get(self): + import tarfile, io + + buf = io.BytesIO() + tar = tarfile.open(mode = 'w:bz2', fileobj = buf) + + def check_add(path, arcname = None): + if os.path.isfile(path): + if arcname is None: arcname = path + tar.add(path, self.basename + '/' + arcname) + + def check_add_basename(path): + check_add(path, os.path.basename(path)) + + check_add_basename(self.app.ctrl.args.log) + check_add_basename(self.app.ctrl.args.log + '.1') + check_add_basename(self.app.ctrl.args.log + '.2') + check_add_basename(self.app.ctrl.args.log + '.3') + check_add('config.json') + check_add('upload/' + self.app.ctrl.state.get('selected', '')) + + tar.close() + + self.write(buf.getvalue()) + + + def set_default_headers(self): + fmt = socket.gethostname() + '-%Y%m%d-%H%M%S' + self.basename = datetime.datetime.now().strftime(fmt) + filename = self.basename + '.tar.bz2' + self.set_header('Content-Disposition', 'filename="%s"' % filename) + self.set_header('Content-Type', 'application/x-bzip2') + + class HostnameHandler(bbctrl.APIHandler): def get(self): self.write_json(socket.gethostname()) @@ -403,6 +443,7 @@ class Web(tornado.web.Application): handlers = [ (r'/websocket', WSConnection), (r'/api/log', LogHandler), + (r'/api/bugreport', BugReportHandler), (r'/api/reboot', RebootHandler), (r'/api/hostname', HostnameHandler), (r'/api/wifi', WifiHandler), diff --git a/src/stylus/style.styl b/src/stylus/style.styl index 3e3197b..8ebfc27 100644 --- a/src/stylus/style.styl +++ b/src/stylus/style.styl @@ -754,6 +754,9 @@ tt.save h2:not(:first-of-type) margin-top 2em + a + text-decoration none + .upgrade-version display inline-block -- 2.27.0