-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprsync.py
67 lines (52 loc) · 1.73 KB
/
prsync.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
import argparse
from Queue import Queue
from threading import Thread
import os
import time
import sys
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument("--workers", type=int, help="number of workers", default=1)
parser.add_argument("--dirs", help="synchronize only dirs from file", default=False)
parser.add_argument("src", help="source directory")
parser.add_argument("dst", help="destination directory")
parser.add_argument("--debug", action="store_true", help="increase output verbosity")
args = parser.parse_args()
RSYNC = ['rsync', '-lptgoDxWd', '--inplace', '--size-only']
start = time.time()
def worker():
while True:
item = q.get()
if args.debug:
print "Syncing {0}/{2} to {1}/{2} ...".format(args.src, args.dst, item)
src = ['{0}/{1}/'.format(args.src, item)]
dst = ['{0}/{1}/'.format(args.dst, item)]
subprocess.call(RSYNC + src + dst)
s.put('.')
if not args.dirs:
for dir in next(os.walk("{0}/{1}".format(args.src, item)))[1]:
q.put("{0}/{1}".format(item, dir))
q.task_done()
def status():
while True:
sys.stdout.write("Directories left / total: {0} / {1}, Time: {2} s \r".format(
q.qsize(), s.qsize(), int(time.time() - start)))
sys.stdout.flush()
time.sleep(1)
s = Queue()
q = Queue()
for i in range(args.workers):
t = Thread(target=worker)
t.daemon = True
t.start()
t = Thread(target=status)
t.daemon = True
t.start()
if args.dirs:
for file in open(args.dirs).read().splitlines():
q.put(file.rstrip())
else:
q.put('/')
q.join()
print("\nTotal time: {0} s, Total directories: {1}".format(int(time.time()-start)), s.qsize())