-
Notifications
You must be signed in to change notification settings - Fork 9
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
Support '-' as STDOUT alias when download files #211
Support '-' as STDOUT alias when download files #211
Conversation
what about
|
Support
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHANGELOG.md
Outdated
### Fixed | ||
|
||
* Fix to support '-' as stdout alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is new feature and not a fix
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both PRs missed an important thing: why and when we use wb+ vs wb. That's messed up and was messed up for years now for no good reason. We have a chance to fix it now but it doesn't seem that we are taking it.
CHANGELOG.md
Outdated
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
## [Unreleased] | |||
|
|||
### Added | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line should not be there
b2/console_tool.py
Outdated
MaxDownloadStreamsMixin, | ||
DownloadCommand, | ||
): | ||
def get_download_info_from_local_filename(self, filename: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_download_info_from_local_filename(self, filename: str): | |
def _get_download_info_from_local_filename(self, filename: str): |
the convention in this file is to prefix protected method names with a _
b2/console_tool.py
Outdated
DownloadCommand, | ||
): | ||
def get_download_info_from_local_filename(self, filename: str): | ||
stdout_file_path = 'CON' if platform.system() == 'Windows' else '/dev/stdout' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should be a (class) const so that it's computed once per program execution and not on every single download call. Here it doesn't matter much because CLI use is one-shot, but generally in terms of how you arrange the code, this should be a constant
b2/console_tool.py
Outdated
return stdout_file_path, 'wb', False | ||
|
||
allow_seeking = filename != stdout_file_path | ||
mode = 'wb+' if allow_seeking else 'wb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be using the same thing for named pipes and it should generally be not CLI but sdk
14bd816
to
900957d
Compare
Fix the stdout_file_path as const of CLASS
7ffef03
to
a4bbc47
Compare
a15c2b3
to
09053e3
Compare
### Fixed | ||
* `--quiet` now will implicitly set `--noProgress` option as well | ||
* Fix failing open non-seekable file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is something wrong grammaticaly with this line
@@ -6,8 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
## [Unreleased] | |||
|
|||
### Deprecated | |||
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think people typically write "in THE future", right?
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 | ||
return self.STDOUT_FILE_PATH | ||
return filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |
return self.STDOUT_FILE_PATH | |
return filename | |
if filename != '-': | |
return filename | |
if not os.path.exists(filename): | |
return self.STDOUT_FILE_PATH | |
self._print_stderr( | |
"WARNING: Filename `-` won't be supported in the future and will be treated as stdout alias." | |
) | |
return filename |
): | ||
STDOUT_FILE_PATH = 'CON' if platform.system() == 'Windows' else '/dev/stdout' | ||
|
||
def _correct_local_filename(self, filename: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method does not correct a local filename, so its name is confusing. It should be renamed in such a way that the reader can figure out what it does without reading the code to understand what it does.
r_end, w_end = os.pipe() | ||
|
||
# Save the current stdout file descriptor for later restoration | ||
stdout_fd = os.dup(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use something like STDOUT_DESCRIPTOR = sys.stdout.fileno()
instead of a hardcoded 1
here
@@ -1210,6 +1210,38 @@ def _test_download_threads(self, download_by, num_threads): | |||
self._run_command(command) | |||
self.assertEqual(b'hello world', self._read_file(local_download)) | |||
|
|||
def test_download_to_non_seekable_file(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have added new logic in _correct_local_filename
, but you haven't added any unit tests for it, while the integration tests for this new feature are insufficient.
No description provided.