Skip to content

Commit

Permalink
Add job speed
Browse files Browse the repository at this point in the history
  • Loading branch information
cbenhagen committed Nov 8, 2019
1 parent 00d9583 commit c9abc70
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions ocopy/cli/ocopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ def cli(overwrite: bool, verify: bool, skip_existing: bool, source: str, destina
if len(destinations) != len({get_mount(d) for d in destinations}):
click.secho(f"Destinations should all be on different drives.", fg="yellow")

start = time.time()
job = CopyJob(Path(source), destinations, overwrite=overwrite, verify=verify, skip_existing=skip_existing)

with click.progressbar(job.progress, length=100, item_show_func=lambda name: name) as progress:
for _ in progress:
pass

stop = time.time()
click.echo(f"\n{size / 1000 / 1000 / (stop - start):.2f} MB/s")
click.echo(f"\n{job.speed / 1000 / 1000:.2f} MB/s")

if job.skipped_files:
click.secho(
Expand Down
7 changes: 7 additions & 0 deletions ocopy/copy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import datetime
import time
from concurrent.futures import as_completed
from concurrent.futures.thread import ThreadPoolExecutor
from dataclasses import dataclass
Expand Down Expand Up @@ -234,6 +235,7 @@ def __init__(
self.total_done = 0
self.current_item = None
self.finished = False
self._start_time = time.time()

if auto_start:
self.start()
Expand All @@ -256,6 +258,11 @@ def _progress_reader(self):
def percent_done(self) -> int:
return round(100 / self.todo_size * self.total_done)

@property
def speed(self) -> float:
now = time.time()
return (self.total_done / 2 if self.verify else self.total_done) / (now - self._start_time)

@property
def progress(self) -> str:
for i in range(1, 101):
Expand Down

0 comments on commit c9abc70

Please sign in to comment.