-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunserver.py
44 lines (37 loc) · 1.23 KB
/
runserver.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
import subprocess
import sys
import signal
import os
class color:
PINK = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
def main():
process = subprocess.Popen("dev_appserver.py .", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = process.stderr
def signal_handler(input_signal, frame):
os.kill(process.pid, signal.SIGTERM)
sys.stdout.write(output.readline())
sys.stdout.write(output.readline())
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
while 1:
line = output.readline().strip('\n')
split_location = str.find(line, ']') + 1
first_part = line[:split_location]
second_part = line[split_location:]
if 'WARNING' in line:
print color.YELLOW + first_part + color.ENDC + second_part
elif 'DEBUG' in line:
print color.BLUE + first_part + color.ENDC + second_part
elif 'INFO' in line:
print color.GREEN + first_part + color.ENDC + second_part
elif 'ERROR' in line:
print color.RED + first_part + color.ENDC + second_part
else:
print line
if __name__ == '__main__':
main()