Skip to content
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

Printing the output path for the downloaded object #240

Closed
Closed
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
12 changes: 10 additions & 2 deletions b2/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,10 +1532,16 @@ class DownloadCommand(
):
""" helper methods for returning results from download commands """

def _print_download_info(self, downloaded_file: DownloadedFile):
def _print_download_info(
self, downloaded_file: DownloadedFile, output_filepath: pathlib.Path
) -> None:
download_version = downloaded_file.download_version
output_filepath_string = 'stdout' if output_filepath == STDOUT_FILEPATH else str(
output_filepath.resolve()
)
self._print_file_attribute('File name', download_version.file_name)
self._print_file_attribute('File id', download_version.id_)
self._print_file_attribute('Output file path', output_filepath_string)
self._print_file_attribute('File size', str(download_version.content_length))
self._print_file_attribute('Content type', download_version.content_type)
self._print_file_attribute('Content sha1', download_version.content_sha1)
Expand Down Expand Up @@ -1686,8 +1692,10 @@ def _run(self, args):
b2_uri, progress_listener, encryption=encryption_setting
)

self._print_download_info(downloaded_file)
output_filepath = self.get_local_output_filepath(args.localFileName, downloaded_file)
self._print_download_info(downloaded_file, output_filepath)
progress_listener.change_description(output_filepath.name)

downloaded_file.save_to(output_filepath)
self._print('Download finished')

Expand Down
1 change: 1 addition & 0 deletions changelog.d/+downloaded-file-name.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensured that the name of the output file is printed.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
argcomplete>=2,<4
arrow>=1.0.2,<2.0.0
b2sdk>=1.28.0,<2
b2sdk>=1.29.0,<2
docutils>=0.18.1
idna~=3.4; platform_system == 'Java'
importlib-metadata~=3.3; python_version < '3.8'
phx-class-registry~=4.0
rst2ansi==0.1.5
tabulate==0.9.0
tqdm~=4.65.0
platformdirs>=3.11.0,<5
platformdirs>=3.11.0,<5
19 changes: 14 additions & 5 deletions test/unit/console_tool/test_download_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
EXPECTED_STDOUT_DOWNLOAD = '''
File name: file1.txt
File id: 9999
Output file path: {output_path}
File size: 11
Content type: b2/x-auto
Content sha1: 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
Expand All @@ -40,7 +41,8 @@ def test_download_file_by_uri__flag_support(b2_cli, uploaded_file, tmp_path, fla

b2_cli.run(
['download-file', flag, 'b2id://9999',
str(output_path)], expected_stdout=expected_stdout
str(output_path)],
expected_stdout=expected_stdout.format(output_path=pathlib.Path(output_path).resolve())
)
assert output_path.read_text() == uploaded_file['content']

Expand All @@ -53,7 +55,10 @@ def test_download_file_by_uri__b2_uri_support(b2_cli, uploaded_file, tmp_path, b
output_path = tmp_path / 'output.txt'

b2_cli.run(
['download-file', b2_uri, str(output_path)], expected_stdout=EXPECTED_STDOUT_DOWNLOAD
['download-file', b2_uri, str(output_path)],
expected_stdout=EXPECTED_STDOUT_DOWNLOAD.format(
output_path=pathlib.Path(output_path).resolve()
)
)
assert output_path.read_text() == uploaded_file['content']

Expand All @@ -73,7 +78,9 @@ def test_download_file_by_name(b2_cli, local_file, uploaded_file, tmp_path, flag
'download-file-by-name', uploaded_file['bucket'], uploaded_file['fileName'],
str(output_path)
],
expected_stdout=EXPECTED_STDOUT_DOWNLOAD,
expected_stdout=EXPECTED_STDOUT_DOWNLOAD.format(
output_path=pathlib.Path(output_path).resolve()
),
expected_stderr=
'WARNING: download-file-by-name command is deprecated. Use download-file instead.\n',
)
Expand All @@ -92,7 +99,7 @@ def test_download_file_by_id(b2_cli, uploaded_file, tmp_path, flag, expected_std

b2_cli.run(
['download-file-by-id', flag, '9999', str(output_path)],
expected_stdout=expected_stdout,
expected_stdout=expected_stdout.format(output_path=pathlib.Path(output_path).resolve()),
expected_stderr=
'WARNING: download-file-by-id command is deprecated. Use download-file instead.\n',
)
Expand Down Expand Up @@ -120,7 +127,9 @@ def reader():
uploaded_file['fileName'],
str(output_path)
],
expected_stdout=EXPECTED_STDOUT_DOWNLOAD,
expected_stdout=EXPECTED_STDOUT_DOWNLOAD.format(
output_path=pathlib.Path(output_path).resolve()
),
expected_stderr=
'WARNING: download-file-by-name command is deprecated. Use download-file instead.\n',
)
Expand Down
9 changes: 8 additions & 1 deletion test/unit/test_console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,10 @@ def test_files_encrypted(self):

# Download by name
local_download1 = os.path.join(temp_dir, 'download1.txt')
expected_stdout = '''
expected_stdout_template = '''
File name: file1.txt
File id: 9999
Output file path: {output_path}
File size: 11
Content type: b2/x-auto
Content sha1: 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
Expand All @@ -986,6 +987,9 @@ def test_files_encrypted(self):
Checksum matches
Download finished
'''
expected_stdout = expected_stdout_template.format(
output_path=pathlib.Path(local_download1).resolve()
)

self._run_command(
['download-file', '--noProgress', 'b2://my-bucket/file1.txt', local_download1],
Expand All @@ -996,6 +1000,9 @@ def test_files_encrypted(self):

# Download file by ID. (Same expected output as downloading by name)
local_download2 = os.path.join(temp_dir, 'download2.txt')
expected_stdout = expected_stdout_template.format(
output_path=pathlib.Path(local_download2).resolve()
)
self._run_command(
['download-file', '--noProgress', 'b2id://9999', local_download2], expected_stdout,
'', 0
Expand Down