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