forked from johnthedebs/basicproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfabfile.py
More file actions
62 lines (53 loc) · 1.72 KB
/
fabfile.py
File metadata and controls
62 lines (53 loc) · 1.72 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
59
60
61
62
import fcntl
import os
import shutil
import subprocess
import sys
import time
from fabric.api import task
commands = [
"compass watch --relative-assets --sass-dir static_source/styles/ --css-dir static_files/css/ --images-dir static_files/img/ --javascripts-dir static_files/js/",
"coffee -o static_files/js/ -w static_source/scripts/",
]
def nb_readline(output):
fd = output.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
try:
return output.readline()
except:
return ""
@task
def watch():
"""
Watch coffee and sass files for changes
"""
processes = []
# Clear existing static files and copy over stuff that doesn't need
# to be processed.
if os.path.exists("./static_files"):
print "Clearing current static files..."
shutil.rmtree("./static_files")
print "Copying library and image files..."
shutil.copytree("./static_source/lib", "./static_files/lib")
shutil.copytree("./static_source/img", "./static_files/img")
print "Starting watchers...\n"
for command in commands:
processes.append(subprocess.Popen(
command,
shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT,
))
line = ''.join([nb_readline(p.stdout) for p in processes])
[p.stdout.flush() for p in processes]
while any(processes):
try:
if line != "":
sys.stdout.write(line)
line = ''.join([nb_readline(p.stdout) for p in processes])
[p.stdout.flush() for p in processes]
time.sleep(0.4)
except KeyboardInterrupt:
break
[p.wait() for p in processes]