forked from jiegec/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsync
executable file
·35 lines (30 loc) · 833 Bytes
/
wsync
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
#!/usr/bin/env python3
import sys
import os
import subprocess
excluded_dirs = []
args = ["fswatch"]
origin = None
i = 1
while i < len(sys.argv):
if sys.argv[i][0] == '-':
if sys.argv[i] == '--exclude':
excluded_dirs.append(sys.argv[i + 1])
args.append("-e")
args.append(sys.argv[i + 1])
i += 2
else:
i += 1
else:
if origin is None:
origin = sys.argv[i]
args.append(origin)
i += 1
print(args)
with subprocess.Popen(args, stdout=subprocess.PIPE) as proc:
while True:
file_changed = proc.stdout.readline().decode('utf-8').strip()
print('File {} changed'.format(file_changed))
cmd = 'rsync ' + ' '.join(sys.argv[1:])
print('Calling {}'.format(cmd))
os.system(cmd)