Skip to content

Commit

Permalink
fix(DiscordTime#64): Fix progress logger error
Browse files Browse the repository at this point in the history
Close DiscordTime#64

This commit fixes the ProgressLogger.send RutimeWarning by adding the
async/await to the methods that needs them.

Signed-off-by: Malbolge <victor.gomes@icomp.ufam.edu.br>
  • Loading branch information
malbolgee committed Feb 29, 2024
1 parent 525520a commit f2e5164
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions modules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
Expand Down
4 changes: 2 additions & 2 deletions modules/progresslogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f2e5164

Please sign in to comment.