-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.py
37 lines (29 loc) · 811 Bytes
/
monitor.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# author Red liu
# auto monitor one file changing to do make
import os, time, sys
# get last modified time
# input a file or a *.xxx
def get_last_mtime(files):
mtime = 0.0
if len(files) == 0:
print("Can't get mtime for %s" % files)
sys.exit(0)
for i in files:
suffix = os.path.splitext(i)[1]
if mtime < os.path.getmtime(i):
mtime = os.path.getmtime(i)
return mtime
if __name__ == '__main__':
if len(os.sys.argv) < 2:
print "Usage: monitor.py xxx.py or *.py"
exit()
mtime = 0.0
while True:
last_mtime = get_last_mtime(os.sys.argv[1:])
if mtime != last_mtime:
print "----------------------------------------------------------"
os.system("make html")
mtime = last_mtime
time.sleep(3)