-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·73 lines (53 loc) · 1.45 KB
/
server.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
from subprocess import call
from os import chdir, getcwd
from threading import Thread
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
class CompileSCSS(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
call([
"sass",
"--watch",
root + "/_assets/_scss:" + root + "/_assets/css"
])
class SimpleServer(Thread):
def __init__(self):
Thread.__init__(self)
self.httpd = None
def run(self):
chdir(root + "/_site")
self.httpd = TCPServer(('', 8000), SimpleHTTPRequestHandler)
self.httpd.serve_forever()
def shutdown(self):
self.httpd.shutdown()
class MyntWatcher(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
chdir(root)
call(["fjord", "watch", "-f", "--base-url=http://127.0.0.1:8000/", root, root + "/_site"])
try:
root = getcwd()
#print(root)
threads = []
scss = CompileSCSS()
threads.append(scss)
scss.start()
myntwatch = MyntWatcher()
threads.append(myntwatch)
myntwatch.start()
serv = SimpleServer()
threads.append(serv)
serv.start()
while True:
pass
except(KeyboardInterrupt, SystemExit):
print("Kill signal received! Killing threads...")
for t in threads:
t.kill_received = True
serv.shutdown()
serv.shutdown()
print("server shutdown?")