-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreview.py
40 lines (29 loc) · 823 Bytes
/
preview.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
import SimpleHTTPServer
import SocketServer
import os
from sys import argv
import signal
from larklib import Site
# set PORT
PORT = 8000
if len(argv) > 1: PORT = int(argv[1])
# get site details
site = Site().config_vars
# get current directory
current_directory = os.getcwd()
# change to output directory
os.chdir( site.output_path )
# set up server
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
# print output
print "Serving on PORT %s \nView in browser at http://localhost:%s" % (PORT, PORT)
# initiate server
httpd.serve_forever()
# change back to original directory
os.chdir( current_directory )
# Free up the port when we kill the server
def signal_handler(signal, frame):
httpd.shutdown()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)