Skip to content
Snippets Groups Projects
Commit 894efe1e authored by Florian Schmidt's avatar Florian Schmidt
Browse files

manager: gui: show error dialog when ln_daemon log save fails

and allow user to try again.

fixes issue https://rmc-github.robotic.dlr.de/common/links_and_nodes/issues/356
parent 69aead15
No related branches found
No related tags found
No related merge requests found
......@@ -488,6 +488,10 @@ class Logger(tracked_object):
os.unlink(filename)
user_cb(data)
cb = return_cb
else:
# test write to target file
with open(filename, "ab+") as fp:
pass
def _save():
self._manager_save_after_download(filename, format, verbose)
......
......@@ -18,11 +18,13 @@
"""
import os
import sys
import math
import numpy as np
import struct
import string
import datetime
import traceback
import pyutils
......@@ -147,6 +149,9 @@ class PortInspector(pyutils.hooked_object):
return self.proxy("call_cb", self.remote_obj.manager_save, cb, *args, **kwargs)
def manager_save(self, cb, filename, **kwargs):
# test write to target file
with open(filename, "ab+") as fp:
pass
def on_data(data=None, exception=None):
if exception is not None: return cb(exception=exception)
with open(filename, "wb") as fp:
......@@ -208,6 +213,22 @@ class PortInspector(pyutils.hooked_object):
def on_log_stop_btn_clicked(self, btn):
self.logger.disable()
def error_dialog(self, msg):
dlg = Gtk.MessageDialog(
self.inspect_window,
Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
message_format=msg
)
dlg.set_markup(msg)
dlg.set_property("use-markup", True)
def answer(dlg, response_id):
dlg.hide()
return
dlg.connect("response", answer)
dlg.show()
def on_log_download_btn_clicked(self, btn):
"""
download and save to local file!
......@@ -272,8 +293,13 @@ class PortInspector(pyutils.hooked_object):
elif exists and self.keep_overwriting_log:
self.info("file %s already exists but user chose to always overwrite..." % self.last_downloaded_file)
self.start_download()
try:
self.start_download()
except:
self.log_download_btn.set_property("sensitive", True)
self.error_dialog("could not download ln_daemon_log:\n%s" % sys.exc_info()[1])
self.error("could not start download of ln_daemon log!\n%s" % traceback.format_exc())
def start_download(self):
self.info("downloading data...")
self.on_retrieve_log()
......@@ -281,10 +307,11 @@ class PortInspector(pyutils.hooked_object):
def on_retrieve_log(self):
fn = self.last_downloaded_file
def _on_finish(exception=None):
self.log_download_btn.set_property("sensitive", True)
if exception is not None:
self.error_dialog("could not download ln_daemon_log:\n%s" % exception)
return self.error("could not manager_save() the log: %s" % exception)
self._update_log_stat_label()
self.log_download_btn.set_property("sensitive", True)
self.info("manager_save to %r finished" % fn)
self.logger.manager_save(_on_finish, fn, verbose=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment