UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?

Sat, 20 Jan 2018 21:27:05 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sat, 20 Jan 2018 21:27:05 +0000
changeset 14
5a988a2c2624
parent 13
1813654427d7
child 15
aaf1a281a3fe

UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?

backup.py file | annotate | diff | comparison | revisions
ui.py file | annotate | diff | comparison | revisions
--- a/backup.py	Sat Jan 20 20:53:28 2018 +0000
+++ b/backup.py	Sat Jan 20 21:27:05 2018 +0000
@@ -106,13 +106,13 @@
             t=status['type']
             #may_indicate_finished=False
             if t=='progress_percent':
-                #may_indicate_finished=True
-                # Temporary output
-                if 'current' not in status:
-                    status['current']=0
-                if 'total' not in status:
-                    status['total']=0
-                print('%d / %d' % (status['current'], status['total']))
+                if 'current' in status and 'total' in status:
+                    with self.lock:
+                        self.current_operation.progress_current=status['current']
+                        self.current_operation.progress_total=status['total']
+                        status, callback=self.__status_unlocked()
+                    if callback:
+                        callback(self, status)
             elif t=='archive_progress':
                 pass
             elif t=='progress_message':
--- a/ui.py	Sat Jan 20 20:53:28 2018 +0000
+++ b/ui.py	Sat Jan 20 21:27:05 2018 +0000
@@ -8,10 +8,22 @@
 import logging
 from threading import Lock
 
-traynames={False: 'B.', True: 'B!'}
+INACTIVE=0
+ACTIVE=1
+ERROR=2
+
+traynames={INACTIVE: 'B.', ACTIVE: 'B!', ERROR: 'B?'}
+
+def combine_state(state1, state2):
+    if state1==ERROR or state2==ERROR:
+        return ERROR
+    elif state1==ACTIVE or state2==ACTIVE:
+        return ACTIVE
+    else:
+        return INACTIVE
 
 def make_title(status):
-    active=False
+    state=INACTIVE
     if status['type']=='scheduled':
         # Operation scheduled
         when=status['when']
@@ -31,17 +43,22 @@
                 whenstr='at %02d:%02d' % (twhen.tm_hour, twhen.tm_min)
         detail=''
         if 'detail' in status and status['detail']:
+            if status['detail']=='retry':
+                state=ERROR
             detail=status['detail']+' '
         title="%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr)
     elif status['type']=='current':
         # Operation running
-        title="%s (running: %s)" % (status['name'], status['operation'])
-        active=True
+        progress=''
+        if 'progress_current' in status and 'progress_total' in status:
+            progress='%d%%' % (status.progress_current/status.progress_total)
+        title="%s (running: %s%s)" % (status['name'], status['operation'], progress)
+        active=ACTIVE
     else: # status['type']=='nothing':
         # Should be unscheduled, nothing running
         title=status['name']
 
-    return title, active
+    return title, state
 
 
 class BorgendTray(rumps.App):
@@ -66,16 +83,16 @@
                 b.set_status_update_callback(cb)
                 self.statuses[index]=b.status()
 
-            menu, active=self.__rebuild_menu()
+            menu, state=self.__rebuild_menu()
 
-            super().__init__(traynames[active], menu=menu, quit_button=None)
+            super().__init__(traynames[state], menu=menu, quit_button=None)
 
     def __rebuild_menu(self):
         menu=[]
-        active=False
+        state=INACTIVE
         for index in range(len(self.backups)):
             b=self.backups[index]
-            title, this_active=make_title(self.statuses[index])
+            title, this_state=make_title(self.statuses[index])
             logging.info('TITLE: %s' % title)
             # Python closures suck dog's balls...
             # first and the last program I write in Python until somebody
@@ -83,12 +100,12 @@
             cbm=lambda sender, _b=b: self.__menu_select_backup(sender, _b)
             item=rumps.MenuItem(title, callback=cbm)
             menu.append(item)
-            active=active or this_active
+            state=combine_state(state, this_state)
 
         menu_quit=rumps.MenuItem("Quit...", callback=self.my_quit)
         menu.append(menu_quit)
 
-        return menu, active
+        return menu, state
 
 
     def my_quit(self, _):
@@ -106,7 +123,6 @@
             logging.debug('Rebuilding menu')
             self.menu.clear()
             menu, active=self.__rebuild_menu()
-            print(active)
             self.menu.update(menu)
             self.title=traynames[active]
 

mercurial