Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: tools/telemetry/third_party/gsutilz/gslib/progress_callback.py

Issue 1376593003: Roll gsutil version to 4.15. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/gsutilz/gslib/progress_callback.py
diff --git a/tools/telemetry/third_party/gsutilz/gslib/progress_callback.py b/tools/telemetry/third_party/gsutilz/gslib/progress_callback.py
index 73ee490be83c484cb6a1cabb935a32a1ed82c8f4..69ee3ed725d62eebbcb658cef5a83703fcae553c 100644
--- a/tools/telemetry/third_party/gsutilz/gslib/progress_callback.py
+++ b/tools/telemetry/third_party/gsutilz/gslib/progress_callback.py
@@ -120,32 +120,41 @@ def ConstructAnnounceText(operation_name, url_string):
class FileProgressCallbackHandler(object):
"""Outputs progress info for large operations like file copy or hash."""
- def __init__(self, announce_text, logger):
+ def __init__(self, announce_text, logger, start_byte=0,
+ override_total_size=None):
"""Initializes the callback handler.
Args:
announce_text: String describing the operation.
logger: For outputting log messages.
+ start_byte: The beginning of the file component, if one is being used.
+ override_total_size: The size of the file component, if one is being used.
"""
self._announce_text = announce_text
self._logger = logger
+ self._start_byte = start_byte
+ self._override_total_size = override_total_size
# Ensures final newline is written once even if we get multiple callbacks.
self._last_byte_written = False
# Function signature is in boto callback format, which cannot be changed.
def call(self, # pylint: disable=invalid-name
- total_bytes_processed,
+ last_byte_processed,
total_size):
"""Prints an overwriting line to stderr describing the operation progress.
Args:
- total_bytes_processed: Number of bytes processed so far.
+ last_byte_processed: The last byte processed in the file. For file
+ components, this number should be in the range
+ [start_byte:start_byte + override_total_size].
total_size: Total size of the ongoing operation.
"""
if not self._logger.isEnabledFor(logging.INFO) or self._last_byte_written:
return
- # Handle streaming case specially where we don't know the total size:
+ if self._override_total_size:
+ total_size = self._override_total_size
+
if total_size:
total_size_string = '/%s' % MakeHumanReadable(total_size)
else:
@@ -155,8 +164,8 @@ class FileProgressCallbackHandler(object):
# TODO: Make this work with logging.Logger.
sys.stderr.write('%s%s%s \r' % (
self._announce_text,
- MakeHumanReadable(total_bytes_processed),
+ MakeHumanReadable(last_byte_processed - self._start_byte),
total_size_string))
- if total_size and total_bytes_processed == total_size:
+ if total_size and last_byte_processed - self._start_byte == total_size:
self._last_byte_written = True
sys.stderr.write('\n')

Powered by Google App Engine
This is Rietveld 408576698