-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtcr
executable file
·59 lines (48 loc) · 1.58 KB
/
tcr
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
#!/usr/bin/env python3
# -*- mode: python -*-
import os
import sys
import argparse
import select
import shlex
import subprocess
import sys
import signal
import time
def run_tests():
return os.system("stack install --fast --test minilang")
def tcr():
if run_tests() == 0:
os.system("git commit -a -m \"working\"")
else:
os.system("git reset --hard HEAD")
# When we receive ctrl-c, kill the watcher
process = None
done = False
def signal_handler(sig, frame):
done = True
if process:
process.kill()
signal.signal(signal.SIGINT, signal_handler)
osname = os.uname().sysname
if osname == 'Darwin':
cmd = "fswatch . --exclude '\.#.*' --exclude 'TAGS' --exclude '.*~' --exclude '/\..+' --exclude '\.newenv.*' --exclude '\.stack-work'"
else:
cmd = "inotifywait -m -r -e modify -e create -e move -e delete . --exclude '\.#.*|.*~|/\..+|\.newenv.*|\.stack-work|TAGS'"
tcr()
while not done:
# start the file watcher subprocess
process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE)
poll = select.poll()
poll.register(process.stdout, select.POLLIN)
# wait for output or subprocess exit
while process.poll() is None:
if poll.poll(1000):
time.sleep(0.5) # debounce because we tend to save lots of files at once
# When we have new output, print it and run the tests
available = process.stdout.peek(1024)
if len(available) > 0:
print(process.stdout.read(len(available)).decode("utf-8"))
tcr()
if process.returncode != 0:
sys.exit(0)