Browse Source

add msgid to progress output

Marian Beermann 8 years ago
parent
commit
d5515b6952
6 changed files with 34 additions and 21 deletions
  1. 8 4
      docs/internals/frontends.rst
  2. 3 2
      src/borg/archive.py
  3. 3 2
      src/borg/archiver.py
  4. 4 3
      src/borg/cache.py
  5. 10 7
      src/borg/helpers.py
  6. 6 3
      src/borg/repository.py

+ 8 - 4
docs/internals/frontends.rst

@@ -44,7 +44,9 @@ progress_message
     saying what is currently worked on.
     saying what is currently worked on.
 
 
     operation
     operation
-        integer ID of the operation
+        unique, opaque integer ID of the operation
+    msgid
+        Message ID of the operation (may be *none*)
     finished
     finished
         boolean indicating whether the operation has finished, only the last object for an *operation*
         boolean indicating whether the operation has finished, only the last object for an *operation*
         can have this property set to *true*.
         can have this property set to *true*.
@@ -52,10 +54,12 @@ progress_message
         current progress message (may be empty/absent)
         current progress message (may be empty/absent)
 
 
 progress_percent
 progress_percent
-    Absolute progress display with defined end/total and current value.
+    Absolute progress information with defined end/total and current value.
 
 
     operation
     operation
-        integer ID of the operation
+        unique, opaque integer ID of the operation
+    msgid
+        Message ID of the operation (may be *none*)
     finished
     finished
         boolean indicating whether the operation has finished, only the last object for an *operation*
         boolean indicating whether the operation has finished, only the last object for an *operation*
         can have this property set to *true*.
         can have this property set to *true*.
@@ -81,7 +85,7 @@ log_message
     created
     created
         Unix timestamp (float)
         Unix timestamp (float)
     levelname
     levelname
-        Upper-case log level name (also called severity). Defined levels are: DEBUG, INFO, WARNING, CRITICAL
+        Upper-case log level name (also called severity). Defined levels are: DEBUG, INFO, WARNING, ERROR, CRITICAL
     name
     name
         Name of the emitting entity
         Name of the emitting entity
     message
     message

+ 3 - 2
src/borg/archive.py

@@ -734,7 +734,7 @@ Utilization of max. archive size: {csize_max:.0%}
         try:
         try:
             unpacker = msgpack.Unpacker(use_list=False)
             unpacker = msgpack.Unpacker(use_list=False)
             items_ids = self.metadata.items
             items_ids = self.metadata.items
-            pi = ProgressIndicatorPercent(total=len(items_ids), msg="Decrementing references %3.0f%%")
+            pi = ProgressIndicatorPercent(total=len(items_ids), msg="Decrementing references %3.0f%%", msgid='archive.delete')
             for (i, (items_id, data)) in enumerate(zip(items_ids, self.repository.get_many(items_ids))):
             for (i, (items_id, data)) in enumerate(zip(items_ids, self.repository.get_many(items_ids))):
                 if progress:
                 if progress:
                     pi.show(i)
                     pi.show(i)
@@ -1153,7 +1153,8 @@ class ArchiveChecker:
         chunks_count_segments = 0
         chunks_count_segments = 0
         errors = 0
         errors = 0
         defect_chunks = []
         defect_chunks = []
-        pi = ProgressIndicatorPercent(total=chunks_count_index, msg="Verifying data %6.2f%%", step=0.01)
+        pi = ProgressIndicatorPercent(total=chunks_count_index, msg="Verifying data %6.2f%%", step=0.01,
+                                      msgid='check.verify_data')
         marker = None
         marker = None
         while True:
         while True:
             chunk_ids = self.repository.scan(limit=100, marker=marker)
             chunk_ids = self.repository.scan(limit=100, marker=marker)

+ 3 - 2
src/borg/archiver.py

@@ -555,7 +555,7 @@ class Archiver:
 
 
         filter = self.build_filter(matcher, peek_and_store_hardlink_masters, strip_components)
         filter = self.build_filter(matcher, peek_and_store_hardlink_masters, strip_components)
         if progress:
         if progress:
-            pi = ProgressIndicatorPercent(msg='%5.1f%% Extracting: %s', step=0.1)
+            pi = ProgressIndicatorPercent(msg='%5.1f%% Extracting: %s', step=0.1, msgid='extract')
             pi.output('Calculating size')
             pi.output('Calculating size')
             extracted_size = sum(item.get_size(hardlink_masters) for item in archive.iter_items(filter))
             extracted_size = sum(item.get_size(hardlink_masters) for item in archive.iter_items(filter))
             pi.total = extracted_size
             pi.total = extracted_size
@@ -589,7 +589,8 @@ class Archiver:
                 self.print_warning('%s: %s', remove_surrogates(orig_path), e)
                 self.print_warning('%s: %s', remove_surrogates(orig_path), e)
 
 
         if not args.dry_run:
         if not args.dry_run:
-            pi = ProgressIndicatorPercent(total=len(dirs), msg='Setting directory permissions %3.0f%%')
+            pi = ProgressIndicatorPercent(total=len(dirs), msg='Setting directory permissions %3.0f%%',
+                                          msgid='extract.permissions')
             while dirs:
             while dirs:
                 pi.show()
                 pi.show()
                 dir_item = dirs.pop(-1)
                 dir_item = dirs.pop(-1)

+ 4 - 3
src/borg/cache.py

@@ -320,7 +320,7 @@ Chunk index:    {0.total_unique_chunks:20d} {0.total_chunks:20d}"""
 
 
     def begin_txn(self):
     def begin_txn(self):
         # Initialize transaction snapshot
         # Initialize transaction snapshot
-        pi = ProgressIndicatorMessage()
+        pi = ProgressIndicatorMessage(msgid='cache.begin_transaction')
         txn_dir = os.path.join(self.path, 'txn.tmp')
         txn_dir = os.path.join(self.path, 'txn.tmp')
         os.mkdir(txn_dir)
         os.mkdir(txn_dir)
         pi.output('Initializing cache transaction: Reading config')
         pi.output('Initializing cache transaction: Reading config')
@@ -340,7 +340,7 @@ Chunk index:    {0.total_unique_chunks:20d} {0.total_chunks:20d}"""
         if not self.txn_active:
         if not self.txn_active:
             return
             return
         self.security_manager.save(self.manifest, self.key, self)
         self.security_manager.save(self.manifest, self.key, self)
-        pi = ProgressIndicatorMessage()
+        pi = ProgressIndicatorMessage(msgid='cache.commit')
         if self.files is not None:
         if self.files is not None:
             if self._newest_mtime is None:
             if self._newest_mtime is None:
                 # was never set because no files were modified/added
                 # was never set because no files were modified/added
@@ -468,7 +468,8 @@ Chunk index:    {0.total_unique_chunks:20d} {0.total_chunks:20d}"""
                 chunk_idx = None
                 chunk_idx = None
                 if self.progress:
                 if self.progress:
                     pi = ProgressIndicatorPercent(total=len(archive_ids), step=0.1,
                     pi = ProgressIndicatorPercent(total=len(archive_ids), step=0.1,
-                                                  msg='%3.0f%% Syncing chunks cache. Processing archive %s')
+                                                  msg='%3.0f%% Syncing chunks cache. Processing archive %s',
+                                                  msgid='cache.sync')
                 for archive_id in archive_ids:
                 for archive_id in archive_ids:
                     archive_name = lookup_name(archive_id)
                     archive_name = lookup_name(archive_id)
                     if self.progress:
                     if self.progress:

+ 10 - 7
src/borg/helpers.py

@@ -1384,13 +1384,15 @@ class ProgressIndicatorBase:
 
 
     @classmethod
     @classmethod
     def operation_id(cls):
     def operation_id(cls):
+        """Unique number, can be used by receiving applications to distinguish different operations."""
         cls.operation_id_counter += 1
         cls.operation_id_counter += 1
         return cls.operation_id_counter
         return cls.operation_id_counter
 
 
-    def __init__(self):
+    def __init__(self, msgid=None):
         self.handler = None
         self.handler = None
         self.logger = logging.getLogger(self.LOGGER)
         self.logger = logging.getLogger(self.LOGGER)
         self.id = self.operation_id()
         self.id = self.operation_id()
+        self.msgid = msgid
 
 
         # If there are no handlers, set one up explicitly because the
         # If there are no handlers, set one up explicitly because the
         # terminator and propagation needs to be set.  If there are,
         # terminator and propagation needs to be set.  If there are,
@@ -1426,12 +1428,13 @@ class ProgressIndicatorBase:
         assert self.json
         assert self.json
         if not self.emit:
         if not self.emit:
             return
             return
-        print(json.dumps(dict(
+        kwargs.update(dict(
             operation=self.id,
             operation=self.id,
+            msgid=self.msgid,
             type=self.JSON_TYPE,
             type=self.JSON_TYPE,
-            finished=finished,
-            **kwargs,
-        )), file=sys.stderr)
+            finished=finished
+        ))
+        print(json.dumps(kwargs), file=sys.stderr)
 
 
     def finish(self):
     def finish(self):
         if self.json:
         if self.json:
@@ -1461,7 +1464,7 @@ class ProgressIndicatorMessage(ProgressIndicatorBase):
 class ProgressIndicatorPercent(ProgressIndicatorBase):
 class ProgressIndicatorPercent(ProgressIndicatorBase):
     JSON_TYPE = 'progress_percent'
     JSON_TYPE = 'progress_percent'
 
 
-    def __init__(self, total=0, step=5, start=0, msg="%3.0f%%"):
+    def __init__(self, total=0, step=5, start=0, msg="%3.0f%%", msgid=None):
         """
         """
         Percentage-based progress indicator
         Percentage-based progress indicator
 
 
@@ -1476,7 +1479,7 @@ class ProgressIndicatorPercent(ProgressIndicatorBase):
         self.step = step
         self.step = step
         self.msg = msg
         self.msg = msg
 
 
-        super().__init__()
+        super().__init__(msgid=msgid)
 
 
     def progress(self, current=None, increase=1):
     def progress(self, current=None, increase=1):
         if current is not None:
         if current is not None:

+ 6 - 3
src/borg/repository.py

@@ -483,7 +483,8 @@ class Repository:
             unused = []
             unused = []
 
 
         logger.debug('compaction started.')
         logger.debug('compaction started.')
-        pi = ProgressIndicatorPercent(total=len(self.compact), msg='Compacting segments %3.0f%%', step=1)
+        pi = ProgressIndicatorPercent(total=len(self.compact), msg='Compacting segments %3.0f%%', step=1,
+                                      msgid='repository.compact_segments')
         for segment, freeable_space in sorted(self.compact.items()):
         for segment, freeable_space in sorted(self.compact.items()):
             if not self.io.segment_exists(segment):
             if not self.io.segment_exists(segment):
                 logger.warning('segment %d not found, but listed in compaction data', segment)
                 logger.warning('segment %d not found, but listed in compaction data', segment)
@@ -584,7 +585,8 @@ class Repository:
         self.prepare_txn(index_transaction_id, do_cleanup=False)
         self.prepare_txn(index_transaction_id, do_cleanup=False)
         try:
         try:
             segment_count = sum(1 for _ in self.io.segment_iterator())
             segment_count = sum(1 for _ in self.io.segment_iterator())
-            pi = ProgressIndicatorPercent(total=segment_count, msg="Replaying segments %3.0f%%")
+            pi = ProgressIndicatorPercent(total=segment_count, msg='Replaying segments %3.0f%%',
+                                          msgid='repository.replay_segments')
             for i, (segment, filename) in enumerate(self.io.segment_iterator()):
             for i, (segment, filename) in enumerate(self.io.segment_iterator()):
                 pi.show(i)
                 pi.show(i)
                 if index_transaction_id is not None and segment <= index_transaction_id:
                 if index_transaction_id is not None and segment <= index_transaction_id:
@@ -694,7 +696,8 @@ class Repository:
         self.prepare_txn(None)  # self.index, self.compact, self.segments all empty now!
         self.prepare_txn(None)  # self.index, self.compact, self.segments all empty now!
         segment_count = sum(1 for _ in self.io.segment_iterator())
         segment_count = sum(1 for _ in self.io.segment_iterator())
         logger.debug('Found %d segments', segment_count)
         logger.debug('Found %d segments', segment_count)
-        pi = ProgressIndicatorPercent(total=segment_count, msg="Checking segments %3.1f%%", step=0.1)
+        pi = ProgressIndicatorPercent(total=segment_count, msg='Checking segments %3.1f%%', step=0.1,
+                                      msgid='repository.check')
         for i, (segment, filename) in enumerate(self.io.segment_iterator()):
         for i, (segment, filename) in enumerate(self.io.segment_iterator()):
             pi.show(i)
             pi.show(i)
             if segment > transaction_id:
             if segment > transaction_id: