borgend/ui.py

changeset 106
a7bdc239ef62
parent 105
55043f86c0b5
child 110
a79409c72565
--- a/borgend/ui.py	Sun Feb 04 14:37:09 2018 +0000
+++ b/borgend/ui.py	Mon Feb 05 10:25:17 2018 +0000
@@ -15,6 +15,7 @@
 from . import dreamtime
 from . import branding
 from . import loggers
+from .exprotect import protect_noreturn
 from .config import settings
 
 logger=logging.getLogger(__name__)
@@ -83,26 +84,19 @@
 
 
 def progress_percentage(done, total, d):
-    progress=''
-    try:
-        percentage = 100*float(done)/float(total)
-        progress=': %d%%' % int(round(percentage))
-        if 'operation_no' in d:
-            progress=':#%d%s' % (d['operation_no'], progress)
-    except:
-        pass
+    percentage = 100*float(done)/float(total)
+    progress=': %d%%' % int(round(percentage))
+    if 'operation_no' in d:
+        progress=':#%d%s' % (d['operation_no'], progress)
     return progress
 
 def progress_parts(done, total, d):
-    progress=''
-    try:
-        progress=': %d/%d' % (int(done), int(total))
-        if 'operation_no' in d:
-            progress=':#%d%s' % (d['operation_no'], progress)
-    except:
-        pass
+    progress=': %d/%d' % (int(done), int(total))
+    if 'operation_no' in d:
+        progress=':#%d%s' % (d['operation_no'], progress)
     return progress
 
+_error_state=(backup.State.INACTIVE, backup.Errors.ERRORS)
 
 def make_title(status):
     def add_info(info, new):
@@ -282,6 +276,9 @@
 
         return menu, title
 
+    # Callbacks -- exception-protected to get any indications of errors
+
+    @protect_noreturn
     def refresh_ui(self):
         with self.lock:
             menu, title=self.build_menu_and_timer()
@@ -289,6 +286,7 @@
             self.menu.update(menu)
             self.title=title
 
+    @protect_noreturn
     def __status_callback(self, index, status, errorlog=None):
         logger.debug("Tray status callback")
         with self.lock:
@@ -314,10 +312,7 @@
             notification_workaround(branding.appname_stylised,
                                     msgid, errorlog['message'])
 
-    def __sleepwake_callback(self, woke):
-        if woke:
-            self.refresh_ui()
-
+    @protect_noreturn
     def pause_resume_all(self):
         with self.lock:
             try:
@@ -335,9 +330,16 @@
             except:
                 logger.exception("Pause/resume error")
 
+    @protect_noreturn
+    def __sleepwake_callback(self, woke):
+        if woke:
+            self.refresh_ui()
+
+    @protect_noreturn
     def quit(self):
         rumps.quit_application()
 
+    @protect_noreturn
     def __menu_select_backup(self, sender, b):
         #sender.state=not sender.state
         logger.debug("Manually backup '%s'", b.name)

mercurial