-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrefreshOnEdit.py
43 lines (35 loc) · 1.01 KB
/
refreshOnEdit.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
import os
import sys
import time
import subprocess
import fnmatch
file = sys.argv[1]
rootpath = os.getcwd()
files = {}
refreshTime = 1
if file == "":
print "Usage: python refreshOnEdit.py YourFile.py"
exit(0)
#parse directories
def getLastModified():
filesdir = {}
pattern = "*.*"
for root, dirs, curfiles in os.walk(rootpath):
for filename in fnmatch.filter(curfiles, pattern):
pth = os.path.join(root, filename)
filesdir[pth] = os.stat(pth).st_mtime
return filesdir
print "Running %s..." % file
while True:
id = subprocess.Popen(['node', file]) #Open the process in the background
while True:
files = getLastModified()
time.sleep(refreshTime) #check every x seconds for a change
escape = False
for f in files:
if not os.path.isfile(f) or os.stat(f).st_mtime != files[f]:
print "File modified. Reloading..."
escape = True
break
if escape: break
id.kill()