From 47ca4d59cd2a69746af23444df39d9b31192c4e1 Mon Sep 17 00:00:00 2001 From: Maciej Lech Date: Thu, 17 Sep 2020 15:29:17 +0200 Subject: [PATCH] Fix usage of progress listener --- b2/console_tool.py | 32 ++++++++++++++++++-------------- noxfile.py | 5 +++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/b2/console_tool.py b/b2/console_tool.py index d9c16340a..13951c410 100644 --- a/b2/console_tool.py +++ b/b2/console_tool.py @@ -641,7 +641,8 @@ def _setup_parser(cls, parser): def run(self, args): progress_listener = make_progress_listener(args.localFileName, args.noProgress) download_dest = DownloadDestLocalFile(args.localFileName) - self.api.download_file_by_id(args.fileId, download_dest, progress_listener) + with progress_listener: + self.api.download_file_by_id(args.fileId, download_dest, progress_listener) self.console_tool._print_download_info(download_dest) return 0 @@ -669,7 +670,8 @@ def run(self, args): bucket = self.api.get_bucket_by_name(args.bucketName) progress_listener = make_progress_listener(args.localFileName, args.noProgress) download_dest = DownloadDestLocalFile(args.localFileName) - bucket.download_file_by_name(args.b2FileName, download_dest, progress_listener) + with progress_listener: + bucket.download_file_by_name(args.b2FileName, download_dest, progress_listener) self.console_tool._print_download_info(download_dest) return 0 @@ -1442,18 +1444,20 @@ def run(self, args): self.api.services.upload_manager.set_thread_pool_size(args.threads) bucket = self.api.get_bucket_by_name(args.bucketName) - file_info = bucket.upload_local_file( - local_file=args.localFilePath, - file_name=args.b2FileName, - content_type=args.contentType, - file_infos=file_infos, - sha1_sum=args.sha1, - min_part_size=args.minPartSize, - progress_listener=make_progress_listener(args.localFilePath, args.noProgress), - ) - if not args.quiet: - self._print("URL by file name: " + bucket.get_download_url(args.b2FileName)) - self._print("URL by fileId: " + self.api.get_download_url_for_fileid(file_info.id_)) + progress_listener = make_progress_listener(args.localFilePath, args.noProgress) + with progress_listener: + file_info = bucket.upload_local_file( + local_file=args.localFilePath, + file_name=args.b2FileName, + content_type=args.contentType, + file_infos=file_infos, + sha1_sum=args.sha1, + min_part_size=args.minPartSize, + progress_listener=progress_listener, + ) + if not args.quiet: + self._print("URL by file name: " + bucket.get_download_url(args.b2FileName)) + self._print("URL by fileId: " + self.api.get_download_url_for_fileid(file_info.id_)) self._print_json(file_info) return 0 diff --git a/noxfile.py b/noxfile.py index 5fce8aab8..2c077a46a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -112,7 +112,8 @@ def unit(session): 'pytest', '--cov=b2', '--cov-branch', '--cov-report=xml', '--doctest-modules', *session.posargs, 'test/unit' ) - session.notify('cover') + if not session.posargs: + session.notify('cover') @nox.session(python=PYTHON_VERSIONS) @@ -138,7 +139,7 @@ def test(session): def cover(session): """Perform coverage analysis.""" session.install('coverage') - session.run('coverage', 'report', '--fail-under=75', '--show-missing') + session.run('coverage', 'report', '--fail-under=75', '--show-missing', '--skip-covered') session.run('coverage', 'erase')