2021-12-16 13:52:38 +00:00
|
|
|
"""
|
|
|
|
A very minimal `cp` clone that displays a progress bar.
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
|
2022-04-01 13:17:21 +00:00
|
|
|
from rich.progress import Progress
|
2021-12-16 13:52:38 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) == 3:
|
2022-04-01 13:17:21 +00:00
|
|
|
with Progress() as progress:
|
2021-12-16 13:57:46 +00:00
|
|
|
desc = os.path.basename(sys.argv[1])
|
2022-04-01 13:17:21 +00:00
|
|
|
with progress.open(sys.argv[1], "rb", description=desc) as src:
|
2021-12-16 13:52:38 +00:00
|
|
|
with open(sys.argv[2], "wb") as dst:
|
|
|
|
shutil.copyfileobj(src, dst)
|
|
|
|
else:
|
2022-04-01 13:17:21 +00:00
|
|
|
print("Copy a file with a progress bar.")
|
2021-12-16 13:52:38 +00:00
|
|
|
print("Usage:\n\tpython cp_progress.py SRC DST")
|