-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsync.py
More file actions
59 lines (44 loc) · 1.54 KB
/
sync.py
File metadata and controls
59 lines (44 loc) · 1.54 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
47
48
49
50
51
52
53
54
55
56
57
58
import subprocess
import time
import os
import yaml
path = '/home/JDWorkSpace/xxx/ctxmnt/xxx/'
def load_watchlist(path):
with open(path, 'r') as stream:
return yaml.safe_load(stream)
def is_git_updated():
process = subprocess.Popen(["git", "pull", 'origin', 'dev'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# process = subprocess.Popen(["git", "pull", 'origin', 'master'])
output = str(process.communicate()[0])
# print(1)
print(output)
return output.find('file changed') >= -1
def get_mtime(filename):
statbuf = os.stat(filename)
return statbuf.st_mtime
def get_watchlist_time(watchlist):
watchlist_time = []
for i in watchlist:
watchlist_time.append(get_mtime(path + i))
return watchlist_time
def copy_file(file):
subprocess.run(['cp', '-f', path + file, file])
print('start')
watchlist = load_watchlist('watchlist.yml')
watchlist_time = get_watchlist_time(watchlist)
for i in watchlist:
copy_file(i)
while(True):
time.sleep(0.5)
for i,file in enumerate(watchlist):
time.sleep(0.2)
if watchlist_time[i] != get_mtime(path+file):
print('------------start '+ file + '-------------')
watchlist_time[i] = get_mtime(path+file)
copy_file(file)
if(file == 'watchlist.yml'):
watchlist = load_watchlist('watchlist.yml')
watchlist_time = get_watchlist_time(watchlist)
else:
subprocess.run(['python', file])
print('-------------finish--------------')