json progress: emit info (current $something)

This commit is contained in:
Marian Beermann 2017-02-27 22:36:09 +01:00
parent fcad0ddab4
commit d327109604
2 changed files with 11 additions and 4 deletions

View File

@ -22,7 +22,8 @@ where each line is a JSON object. The *type* key of the object determines its ot
Since JSON can only encode text, any string representing a file system path may miss non-text parts. Since JSON can only encode text, any string representing a file system path may miss non-text parts.
The following types are in use: The following types are in use. Progress information is governed by the usual rules for progress information,
it is not produced unless ``--progress`` is specified.
archive_progress archive_progress
Output during operations creating archives (:ref:`borg_create` and :ref:`borg_recreate`). Output during operations creating archives (:ref:`borg_create` and :ref:`borg_recreate`).
@ -67,6 +68,8 @@ progress_percent
A formatted progress message, this will include the percentage and perhaps other information A formatted progress message, this will include the percentage and perhaps other information
current current
Current value (always less-or-equal to *total*) Current value (always less-or-equal to *total*)
info
Array that describes the current item, may be *none*, contents depend on *msgid*
total total
Total value Total value
@ -218,10 +221,14 @@ Operations
- cache.begin_transaction - cache.begin_transaction
- cache.commit - cache.commit
- cache.sync - cache.sync
*info* is one string element, the name of the archive currently synced.
- repository.compact_segments - repository.compact_segments
- repository.replay_segments - repository.replay_segments
- repository.check_segments - repository.check_segments
- check.verify_data - check.verify_data
- extract - extract
*info* is one string element, the name of the path currently extracted.
- extract.permissions - extract.permissions
- archive.delete - archive.delete

View File

@ -1508,13 +1508,13 @@ class ProgressIndicatorPercent(ProgressIndicatorBase):
if terminal_space != -1: if terminal_space != -1:
space = terminal_space - len(self.msg % tuple([pct] + info[:-1] + [''])) space = terminal_space - len(self.msg % tuple([pct] + info[:-1] + ['']))
info[-1] = ellipsis_truncate(info[-1], space) info[-1] = ellipsis_truncate(info[-1], space)
return self.output(self.msg % tuple([pct] + info), justify=False) return self.output(self.msg % tuple([pct] + info), justify=False, info=info)
return self.output(self.msg % pct) return self.output(self.msg % pct)
def output(self, message, justify=True): def output(self, message, justify=True, info=None):
if self.json: if self.json:
self.output_json(message=message, current=self.counter, total=self.total) self.output_json(message=message, current=self.counter, total=self.total, info=info)
else: else:
if justify: if justify:
message = justify_to_terminal_size(message) message = justify_to_terminal_size(message)