MCPcopy
hub / github.com/borgbackup/borg / ProgressIndicatorPercent

Class ProgressIndicatorPercent

src/borg/helpers/progress.py:44–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class ProgressIndicatorPercent(ProgressIndicatorBase):
45 JSON_TYPE = "progress_percent"
46
47 def __init__(self, total=0, step=5, start=0, msg="%3.0f%%", msgid=None):
48 """
49 Percentage-based progress indicator.
50
51 :param total: total amount of items.
52 :param step: step size in percent.
53 :param start: at which percent value to start.
54 :param msg: output message; must contain one %f placeholder for the percentage.
55 """
56 self.counter = 0 # 0 .. (total-1)
57 self.total = total
58 self.trigger_at = start # output next percentage value when reaching (at least) this
59 self.step = step
60 self.msg = msg
61
62 super().__init__(msgid=msgid)
63
64 def progress(self, current=None, increase=1):
65 if current is not None:
66 self.counter = current
67 pct = self.counter * 100 / self.total
68 self.counter += increase
69 if pct >= self.trigger_at:
70 self.trigger_at += self.step
71 return pct
72
73 def show(self, current=None, increase=1, info=None):
74 """
75 Show and output the progress message.
76
77 :param current: Set the current percentage. [None]
78 :param increase: Increase the current percentage. [None]
79 :param info: Array of strings to be formatted with msg. [None]
80 """
81 pct = self.progress(current, increase)
82 if pct is not None:
83 if info is not None:
84 return self.output(self.msg % tuple([pct] + info), info=info)
85 else:
86 return self.output(self.msg % pct)
87
88 def output(self, message, info=None):
89 j = self.make_json(message=message, current=self.counter, total=self.total, info=info)
90 self.logger.info(j)

Callers 15

compact_segmentsMethod · 0.85
replay_segmentsMethod · 0.85
checkMethod · 0.85
verify_dataMethod · 0.85
rebuild_archivesMethod · 0.85
analyze_archivesMethod · 0.85
report_and_deleteMethod · 0.85
do_extractMethod · 0.85
do_repo_compressMethod · 0.85
do_pruneMethod · 0.85
analyze_archivesMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_progress_percentageFunction · 0.68