-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcp_progress.py
More file actions
executable file
·46 lines (38 loc) · 1.11 KB
/
Copy pathcp_progress.py
File metadata and controls
executable file
·46 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
# @Author: Aldo Sotolongo
# @Date: 2016-05-25T14:22:58-04:00
# @Email: aldenso@gmail.com
# @Last modified by: Aldo Sotolongo
# @Last modified time: 2016-08-21T23:49:39-04:00
# Description: simple cp script with progress status, make sure you set the
# filename for destiny.
# example: cp_progress.py ../../file1.txt /tmp/file1.txt
import os
import sys
from subprocess import Popen
from time import sleep
# Origin and destiny files are pass as arguments
argv1 = sys.argv[1]
argv2 = sys.argv[2]
orig_size = os.path.getsize(argv1)
size = 0
def porcent(size):
x = (size * 100) / orig_size
return x
def main():
task = 'RUNNING'
Popen(["cp", argv1, argv2], shell=False)
sleep(0.1)
while task == 'RUNNING':
sleep(0.5)
size = os.path.getsize(argv2)
if size == orig_size:
sys.stdout.write("\rCopying File 100%")
print("\nCopy done")
task = 'DONE'
else:
value = porcent(size)
sys.stdout.write("\rCopying File {}%".format(value))
sys.stdout.flush()
if __name__ == "__main__":
main()