Skip to content

Commit

Permalink
Fix the logic of download file and Updated CHANGELOG
Browse files Browse the repository at this point in the history
Fix the stdout_file_path as const of CLASS
  • Loading branch information
athakur-reef committed Oct 18, 2023
1 parent 3c2e9af commit 900957d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
### Deprecated

* Support '-' as stdout alias
* Support of `-` as a valid filename in `download-file-by-name` or `download-file-by-id` command. In future `-` will be an alias for standard output.

### Fixed

* Fix unable to use '/dev/stdout' by checking the localFileName if that present the `STDOUT` of OS
* Fix unable to use `/dev/stdout` by checking the localFileName if that present the `STDOUT` of OS

### Infrastructure
* Fix gathering licenses of typeshed libraries
Expand Down
26 changes: 9 additions & 17 deletions b2/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,21 +1369,17 @@ class DownloadFileMixin(
MaxDownloadStreamsMixin,
DownloadCommand,
):
def get_download_info_from_local_filename(self, filename: str):
stdout_file_path = 'CON' if platform.system() == 'Windows' else '/dev/stdout'
STDOUT_FILE_PATH = 'CON' if platform.system() == 'Windows' else '/dev/stdout'

def _correct_local_filename(self, filename: str):
if filename == '-':
if os.path.exists('-'):
self._print_stderr(
"WARNING: Filename `-` won't be supported in the future and will be treated as stdout alias."
)
return filename, 'wb+', True
return stdout_file_path, 'wb', False

allow_seeking = filename != stdout_file_path
mode = 'wb+' if allow_seeking else 'wb'

return filename, mode, allow_seeking
return filename
return self.STDOUT_FILE_PATH
return filename


@B2.register_subcommand
Expand Down Expand Up @@ -1413,9 +1409,7 @@ def _setup_parser(cls, parser):
super()._setup_parser(parser)

def run(self, args):
local_filename, mode, allow_seeking = self.get_download_info_from_local_filename(
args.localFileName
)
local_filename = self._correct_local_filename(args.localFileName)

progress_listener = make_progress_listener(local_filename, args.noProgress)
encryption_setting = self._get_source_sse_setting(args)
Expand All @@ -1424,7 +1418,7 @@ def run(self, args):
args.fileId, progress_listener, encryption=encryption_setting
)
self._print_download_info(downloaded_file)
downloaded_file.save_to(local_filename, mode, allow_seeking)
downloaded_file.save_to(local_filename)
self._print('Download finished')
return 0

Expand Down Expand Up @@ -1456,9 +1450,7 @@ def _setup_parser(cls, parser):
super()._setup_parser(parser)

def run(self, args):
local_filename, mode, allow_seeking = self.get_download_info_from_local_filename(
args.localFileName
)
local_filename = self._correct_local_filename(args.localFileName)

self._set_threads_from_args(args)
bucket = self.api.get_bucket_by_name(args.bucketName)
Expand All @@ -1468,7 +1460,7 @@ def run(self, args):
args.b2FileName, progress_listener, encryption=encryption_setting
)
self._print_download_info(downloaded_file)
downloaded_file.save_to(local_filename, mode, allow_seeking)
downloaded_file.save_to(local_filename, 'wb', True)
self._print('Download finished')
return 0

Expand Down

0 comments on commit 900957d

Please sign in to comment.