Skip to content

Commit

Permalink
progress bar for file prep
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Feb 12, 2024
1 parent 6a3edeb commit 09cc475
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions dvuploader/dvuploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rich.progress import Progress, TaskID
from rich.table import Table
from rich.console import Console
from rich.panel import Panel

from dvuploader.directupload import (
TICKET_ENDPOINT,
Expand Down Expand Up @@ -53,7 +54,23 @@ def upload(
Returns:
None
"""
# Validate and hash files

print("\n")
info = "\n".join(
[
f"PID: [bold]{persistent_id}[/bold]", # type: ignore
f"Files: {len(self.files)}",
]
)

panel = Panel(
info,
title="[bold]DVUploader[/bold]",
expand=False,
)

rich.print(panel)

asyncio.run(self._validate_and_hash_files())

# Check for duplicates
Expand Down Expand Up @@ -127,15 +144,35 @@ async def _validate_and_hash_files(self):
None
"""

rich.print("\n[italic white]📝 Preparing upload\n")
print("\n")

tasks = [self._validate_and_hash_file(file=file) for file in self.files]
progress = Progress()
task = progress.add_task(
"[bold italic white]📦 Preparing upload[/bold italic white]",
total=len(self.files),
)
with progress:
tasks = [
self._validate_and_hash_file(
file=file,
progress=progress,
task_id=task,
)
for file in self.files
]

await asyncio.gather(*tasks)
await asyncio.gather(*tasks)

print("\n")

@staticmethod
async def _validate_and_hash_file(file: File):
async def _validate_and_hash_file(
file: File,
progress: Progress,
task_id: TaskID,
):
file.extract_filename_hash_file()
progress.update(task_id, advance=1)

def _check_duplicates(
self,
Expand Down

0 comments on commit 09cc475

Please sign in to comment.