Skip to content

[v2] S3 progress indicator frequency #9545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: cli-accessibility
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 40 additions & 13 deletions awscli/customizations/s3/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ class ResultPrinter(BaseResultHandler):
SRC_DEST_TRANSFER_LOCATION_FORMAT = '{src} to {dest}'
SRC_TRANSFER_LOCATION_FORMAT = '{src}'

def __init__(self, result_recorder, out_file=None, error_file=None):
def __init__(
self, result_recorder, out_file=None, error_file=None, frequency=0, oneline=True
):
"""Prints status of ongoing transfer

:type result_recorder: ResultRecorder
Expand All @@ -331,6 +333,8 @@ def __init__(self, result_recorder, out_file=None, error_file=None):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add docs for frequency and oneline?

self._result_recorder = result_recorder
self._out_file = out_file
self._frequency = frequency
self._first = True
if self._out_file is None:
self._out_file = sys.stdout
self._error_file = error_file
Expand All @@ -347,12 +351,31 @@ def __init__(self, result_recorder, out_file=None, error_file=None):
DryRunResult: self._print_dry_run,
FinalTotalSubmissionsResult: self._clear_progress_if_no_more_expected_transfers,
}
self._now = time.time()
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: seems this initial value is never used, consider initializing to None

self._oneline = oneline

def __call__(self, result):
"""Print the progress of the ongoing transfer based on a result"""
self._result_handler_map.get(type(result), self._print_noop)(
result=result
)
result_handler = self._result_handler_map.get(type(result), self._print_noop)
if type(result) is ProgressResult:
result_handler = self._override_progress_result_handler(
result, result_handler
)
result_handler(result=result)

def _override_progress_result_handler(self, result, result_handler):
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking question: have we considered modifying _print_progress to check frequency and first with a similar check, and only print as needed, instead of adding a new override handler function?

if (
type(result) in [ProgressResult]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could this be type(result) is ProgressResult to be consistent with the same check in __call__ ?

and (
self._first
or (self._frequency == 0)
or (time.time() - self._now >= self._frequency)
)
):
self._now = time.time()
self._first = False
return result_handler
return self._print_noop

def _print_noop(self, **kwargs):
# If the result does not have a handler, then do nothing with it.
Expand Down Expand Up @@ -463,15 +486,19 @@ def _print_progress(self, **kwargs):
if not self._result_recorder.expected_totals_are_final():
progress_statement += self._STILL_CALCULATING_TOTALS

# Make sure that it overrides any previous progress bar.
progress_statement = self._adjust_statement_padding(
progress_statement, ending_char='\r'
)
# We do not want to include the carriage return in this calculation
# as progress length is used for determining whitespace padding.
# So we subtract one off of the length.
self._progress_length = len(progress_statement) - 1

if self._oneline:
# Make sure that it overrides any previous progress bar.
progress_statement = self._adjust_statement_padding(
progress_statement, ending_char='\r'
)
# We do not want to include the carriage return in this calculation
# as progress length is used for determining whitespace padding.
# So we subtract one off of the length.
self._progress_length = len(progress_statement) - 1
else:
progress_statement = self._adjust_statement_padding(
progress_statement, ending_char='\n'
)
# Print the progress out.
self._print_to_out_file(progress_statement)

Expand Down
6 changes: 5 additions & 1 deletion awscli/customizations/s3/s3handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ def _add_result_printer(self, result_recorder, result_processor_handlers):
elif not self._cli_params.get('progress'):
result_printer = NoProgressResultPrinter(result_recorder)
else:
result_printer = ResultPrinter(result_recorder)
result_printer = ResultPrinter(
result_recorder,
frequency=self._cli_params.get('progress_frequency'),
oneline=not self._cli_params.get('progress_multiline'),
)
result_processor_handlers.append(result_printer)


Expand Down
24 changes: 24 additions & 0 deletions awscli/customizations/s3/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,28 @@
),
}

PROGRESS_FREQUENCY = {
'name': 'progress-frequency',
'dest': 'progress_frequency',
'cli_type_name': 'integer',
'default': 0,
'help_text': (
'Number of seconds to wait before updating file '
'transfer progress. This flag is only applied when '
'the quiet and only-show-errors flags are not '
'provided.'
),
}

PROGRESS_MULTILINE = {
'name': 'progress-multiline',
'dest': 'progress_multiline',
'action': 'store_true',
'help_text': (
'Show progress on multiple lines.'
),
}


EXPECTED_SIZE = {
'name': 'expected-size',
Expand Down Expand Up @@ -669,6 +691,8 @@
SOURCE_REGION,
ONLY_SHOW_ERRORS,
NO_PROGRESS,
PROGRESS_FREQUENCY,
PROGRESS_MULTILINE,
PAGE_SIZE,
IGNORE_GLACIER_WARNINGS,
FORCE_GLACIER_TRANSFER,
Expand Down
Loading