backup.py

changeset 15
aaf1a281a3fe
parent 14
5a988a2c2624
child 16
d0ffae5550ef
--- a/backup.py	Sat Jan 20 21:27:05 2018 +0000
+++ b/backup.py	Sat Jan 20 21:52:16 2018 +0000
@@ -23,6 +23,14 @@
     else:
         return logging.ERROR
 
+def safe_get_int(t, x):
+    if x in t:
+        tmp=t[x]
+        if isinstance(tmp, int):
+            return tmp
+    return None
+
+
 class Backup:
 
     def __decode_config(self, cfg):
@@ -104,22 +112,36 @@
         for status in iter(self.borg_instance.read_log, None):
             logging.debug(str(status))
             t=status['type']
-            #may_indicate_finished=False
+
+            errors_this_message=False
+            callback=None
+
             if t=='progress_percent':
-                if 'current' in status and 'total' in status:
+                current=safe_get_int(status, 'current')
+                total=safe_get_int(status, 'total')
+                if current is not None and total is not None:
                     with self.lock:
-                        self.current_operation.progress_current=status['current']
-                        self.current_operation.progress_total=status['total']
+                        self.current_operation.progress_current=current
+                        self.current_operation.progress_total=total
                         status, callback=self.__status_unlocked()
-                    if callback:
-                        callback(self, status)
+
             elif t=='archive_progress':
+                original_size=safe_get_int(status, 'original_size')
+                compressed_size=safe_get_int(status, 'compressed_size')
+                deduplicated_size=safe_get_int(status, 'deduplicated_size')
+                if original_size is not None and original_size is not None and deduplicated_size is not None:
+                    with self.lock:
+                        self.current_operation.original_size=original_size
+                        self.current_operation.compressed_size=compressed_size
+                        self.current_operation.deduplicated_size=deduplicated_size
+                        status, callback=self.__status_unlocked()
+
+            elif t=='progress_message':
                 pass
-            elif t=='progress_message':
-                #may_indicate_finished=True
-                pass
+
             elif t=='file_status':
                 pass
+
             elif t=='log_message':
                 if 'levelname' not in status:
                     status['levelname']='ERROR'
@@ -127,13 +149,22 @@
                     status['message']='UNKNOWN'
                 if 'name' not in status:
                     status['name']='borg'
-                logging.log(translate_loglevel(status['levelname']),
-                            status['name'] + ': ' + status['message'])
-                # set success=False?
+                lvl=translate_loglevel(status['levelname'])
+                logging.log(lvl, status['name'] + ': ' + status['message'])
+                if lvl>=logging.WARNING:
+                    errors_this_message=True
             elif t=='exception':
-                success=False
+                errors_this_message=True
             elif t=='unparsed_error':
-                success=False
+                errors_this_message=True
+
+            if errors_this_message:
+                with self.lock:
+                    self.current_operation.errors=True
+                    status, callback=self.__status_unlocked()
+
+            if callback:
+                callback(self, status)
 
         logging.debug('Waiting for borg subprocess to terminate in log thread')
 
@@ -359,6 +390,9 @@
 
         status['name']=self.name
 
+        if 'errors' not in status:
+            status['errors']=False
+
         if 'when_monotonic' in status:
             status['when']=(status['when_monotonic']
                             -time.monotonic()+time.time())

mercurial