borgend/ui.py

changeset 98
9052e427ea39
parent 97
96d5adbe0205
child 99
281bab8361c8
--- a/borgend/ui.py	Wed Jan 31 00:06:54 2018 +0000
+++ b/borgend/ui.py	Wed Jan 31 22:32:11 2018 +0000
@@ -20,6 +20,7 @@
 
 traynames_ok={
     backup.State.INACTIVE: 'B.',
+    backup.State.PAUSED: 'B‖',
     backup.State.SCHEDULED: 'B.',
     backup.State.QUEUED: 'B:',
     backup.State.ACTIVE: 'B!',
@@ -115,7 +116,9 @@
     if not status.errors.ok():
         info=add_info(info, str(status.errors))
 
-    if status.state==backup.State.SCHEDULED:
+    if status.state==backup.State.PAUSED:
+        info=add_info(info, "paused")
+    elif status.state==backup.State.SCHEDULED:
         # Operation scheduled
         when=status.when()
         now=time.time()
@@ -210,6 +213,8 @@
         menu=[]
         state=(backup.State.INACTIVE, backup.Errors.OK)
         need_reconstruct=None
+        all_paused=True
+
         for index in range(len(self.backups)):
             b=self.backups[index]
             title, this_state, this_need_reconstruct=make_title(self.statuses[index])
@@ -225,6 +230,8 @@
             menu.append(item)
             state=combine_state(state, this_state)
 
+            all_paused=(all_paused and this_state[0]==backup.State.PAUSED)
+
             # Do we have to automatically update menu display?
             if not need_reconstruct:
                 need_reconstruct=this_need_reconstruct
@@ -234,6 +241,13 @@
         menu_log=rumps.MenuItem("Show log", callback=lambda _: showlog())
         menu.append(menu_log)
 
+        if all_paused:
+            pausename='Resume all'
+        else:
+            pausename="Pause all"
+        menu_pause=rumps.MenuItem(pausename, callback=lambda _: self.pause_resume_all())
+        menu.append(menu_pause)
+
         if not settings['no_quit_menu_entry']:
             menu_quit=rumps.MenuItem("Quit...", callback=lambda _: self.quit())
             menu.append(menu_quit)
@@ -290,6 +304,23 @@
             notification_workaround(branding.appname_stylised,
                                     msgid, errorlog['message'])
 
+    def pause_resume_all(self):
+        with self.lock:
+            try:
+                all_paused=True
+                for b in self.backups:
+                    all_paused=all_paused and b.is_paused()
+                if all_paused:
+                    logger.debug('Pausing all')
+                    for b in self.backups:
+                        b.resume()
+                else:
+                    logger.debug('Resuming all')
+                    for b in self.backups:
+                        b.pause()
+            except:
+                logger.exception("Pause/resume error")
+
     def quit(self):
         rumps.quit_application()
 

mercurial