Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/borg/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from .process import daemonize, daemonizing, ThreadRunner
from .process import signal_handler, raising_signal_handler, sig_int, ignore_sigint, SigHup, SigTerm
from .process import popen_with_error_handling, is_terminal, prepare_subprocess_env, create_filter_process
from .progress import ProgressIndicatorPercent, ProgressIndicatorMessage
from .progress import ProgressIndicatorPercent, ProgressIndicatorMessage, ProgressIndicatorObjectCounter
from .time import parse_timestamp, timestamp, safe_timestamp, safe_s, safe_ns, MAX_S, SUPPORT_32BIT_PLATFORMS
from .time import format_time, format_timedelta, OutputTimestamp, archive_ts_now
from .yes_no import yes, TRUISH, FALSISH, DEFAULTISH
Expand Down
34 changes: 33 additions & 1 deletion src/borg/helpers/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ProgressIndicatorBase:
LOGGER = "borg.output.progress"
JSON_TYPE: str = None
JSON_TYPE: str = None # type: ignore[assignment]
Comment thread
ThomasWaldmann marked this conversation as resolved.
Outdated

operation_id_counter = 0

Expand Down Expand Up @@ -41,6 +41,38 @@ def output(self, msg):
self.logger.info(j)


class ProgressIndicatorObjectCounter(ProgressIndicatorBase):
JSON_TYPE = "progress_message"
Comment thread
ThomasWaldmann marked this conversation as resolved.
Outdated

def __init__(self, step=1000, msg="%d objects", msgid=None):
Comment thread
ThomasWaldmann marked this conversation as resolved.
Outdated
"""
Activity-based progress indicator, simply tracking a changing count.

:param step: step size
:param msg: output message; must contain one %d placeholder for the count.
"""
self.step = step
self.msg = msg
self.trigger_at = step
super().__init__(msgid=msgid)

def show(self, current=None):
Comment thread
ThomasWaldmann marked this conversation as resolved.
Outdated
"""
Show and output the progress message if the step condition is met.

:param current: Set the current counter value.
"""
if current is not None and current >= self.trigger_at:
Comment on lines +66 to 71

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize self.counter = 0 in init method, so you don't need that hasattr.

also, move the code that is not related to producing output to a progress method as you see in the percent pi.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sagar-h007 seen this? ^

# adjust trigger_at to the next step threshold
while self.trigger_at <= current:
self.trigger_at += self.step
return self.output(self.msg % current)

def output(self, message):
j = self.make_json(message=message)
self.logger.info(j)


class ProgressIndicatorPercent(ProgressIndicatorBase):
JSON_TYPE = "progress_percent"

Expand Down
7 changes: 5 additions & 2 deletions src/borg/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .hashindex import ChunkIndex, ChunkIndexEntry
from .helpers import Error, ErrorWithTraceback, IntegrityError
from .helpers import Location
from .helpers import bin_to_hex, hex_to_bin
from .helpers import bin_to_hex, hex_to_bin, ProgressIndicatorObjectCounter
from .storelocking import Lock
from .logger import create_logger
from .manifest import NoManifestError
Expand Down Expand Up @@ -317,7 +317,7 @@ def check_object(obj):
else:
log_error("too small.")

# TODO: progress indicator, ...
pi = ProgressIndicatorObjectCounter(step=1000, msg="Checking objects: %d", msgid="repository.check")
Comment thread
ThomasWaldmann marked this conversation as resolved.
Outdated
partial = bool(max_duration)
assert not (repair and partial)
mode = "partial" if partial else "full"
Expand Down Expand Up @@ -364,6 +364,7 @@ def check_object(obj):
obj_corrupted = False
check_object(obj)
objs_checked += 1
pi.show(objs_checked)
Comment thread
ThomasWaldmann marked this conversation as resolved.
Outdated
if obj_corrupted:
objs_errors += 1
if repair:
Expand Down Expand Up @@ -397,6 +398,7 @@ def check_object(obj):
self.store.store(LAST_KEY_CHECKED, key.encode())
break
else:
pi.finish()
Comment thread
ThomasWaldmann marked this conversation as resolved.
Outdated
logger.info("Finished repository check.")
try:
self.store.delete(LAST_KEY_CHECKED)
Expand All @@ -411,6 +413,7 @@ def check_object(obj):
)
except StoreObjectNotFound:
# it can be that there is no "data/" at all, then it crashes when iterating infos.
pi.finish()
pass
Comment thread
ThomasWaldmann marked this conversation as resolved.
Outdated
logger.info(f"Checked {objs_checked} repository objects, {objs_errors} errors.")
if objs_errors == 0:
Expand Down
Loading