From f2e5164bacd9f7c79e7f0e6c493d5f39ae10c6b2 Mon Sep 17 00:00:00 2001 From: Malbolge Date: Thu, 29 Feb 2024 16:48:48 -0400 Subject: [PATCH] fix(#64): Fix progress logger error Close #64 This commit fixes the ProgressLogger.send RutimeWarning by adding the async/await to the methods that needs them. Signed-off-by: Malbolge --- modules/command.py | 11 +++++------ modules/progresslogger.py | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/command.py b/modules/command.py index df0dd27..d340cfe 100644 --- a/modules/command.py +++ b/modules/command.py @@ -212,7 +212,7 @@ def add_to_subparser(subparsers): ) async def execute(self): - self.upload() + await self.upload() def get_filepath(self): files = self.args.file @@ -223,28 +223,27 @@ def get_filepath(self): return files[0] @staticmethod - def _conclude_operation_while_logging(task, title): + async def _conclude_operation_while_logging(task, title): try: with ProgressLogger(title) as progress_logger: result = None while not result: status, result = task.next_chunk() if status: - progress = Progress(status.resumable_progress, status.total_size) - progress_logger.send(progress) + await progress_logger.log_progress(Progress(status.resumable_progress, status.total_size)) return result except BaseException as err: print('\x1b[2K', end='\r') print(f'An error happened while running operation {title}') logger.d(err) - def upload(self): + async def upload(self): try: filepath = self.get_filepath() mimetype = guess_mimetype(filepath) upload_task = self.google.upload(filepath, mimetype) print("Uploading 0%", end='\r') - response = self._conclude_operation_while_logging(upload_task, "Uploading") + response = await self._conclude_operation_while_logging(upload_task, "Uploading") if not response: return print("Upload finished.") diff --git a/modules/progresslogger.py b/modules/progresslogger.py index e25f2e6..70c166c 100644 --- a/modules/progresslogger.py +++ b/modules/progresslogger.py @@ -128,9 +128,9 @@ async def send(self, status: Progress): async def _work(self): """Print logs while the channel is open and receiving values, or closed, but still has items.""" async for progress in self._channel: - self._log_progress(progress) + await self.log_progress(progress) - def _log_progress(self, progress: Progress): + async def log_progress(self, progress: Progress): """Print log from status.""" current_size, total_size, percentage = progress elapsed_time = time.time() - self._start_time