Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1759 from althonos/progress-reader
Add API to support tracking progress while reading from a file
- Loading branch information
Showing
6 changed files
with
659 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
A very minimal `cp` clone that displays a progress bar. | ||
""" | ||
import os | ||
import shutil | ||
import sys | ||
|
||
from rich.progress import ( | ||
BarColumn, | ||
DownloadColumn, | ||
Progress, | ||
TaskID, | ||
TextColumn, | ||
TimeRemainingColumn, | ||
TransferSpeedColumn, | ||
) | ||
|
||
progress = Progress( | ||
TextColumn("[bold blue]{task.description}", justify="right"), | ||
BarColumn(bar_width=None), | ||
"[progress.percentage]{task.percentage:>3.1f}%", | ||
"•", | ||
DownloadColumn(), | ||
"•", | ||
TransferSpeedColumn(), | ||
"•", | ||
TimeRemainingColumn(), | ||
) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) == 3: | ||
|
||
with progress: | ||
desc = os.path.basename(sys.argv[1]) | ||
with progress.read(sys.argv[1], description=desc) as src: | ||
with open(sys.argv[2], "wb") as dst: | ||
shutil.copyfileobj(src, dst) | ||
else: | ||
print("Usage:\n\tpython cp_progress.py SRC DST") |
Oops, something went wrong.