deploy.py 1.07 KB
Newer Older
JackV's avatar
JackV committed
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
#!/usr/bin/env python3

import sys
from time import sleep
from threading import Thread
from argparse import ArgumentParser
from socketserver import TCPServer
from http.server import SimpleHTTPRequestHandler as Handler
import webbrowser


DEFAULT_ADDR = '127.0.0.1'
DEFAULT_PORT = 8080

parser = ArgumentParser(description="Serve reveal.js slides.")
parser.add_argument('port', metavar='PORT', type=int, nargs='?',
                    default=DEFAULT_PORT)
parser.add_argument('--show', action='store_true', default=False,
                    help="Open in browser.")
arg = parser.parse_args()


def httpd_t():
    print("Serving at http://{}:{}".format(DEFAULT_ADDR, arg.port))
    s = TCPServer((DEFAULT_ADDR, arg.port), Handler)
    s.serve_forever()


def show():
    webbrowser.open("http://{}:{}/".format(DEFAULT_ADDR, arg.port))


if __name__ == '__main__':
    httpd = Thread(target=httpd_t)
    httpd.daemon = True
    httpd.start()

    if arg.show:
        show()

    try:
        while True:
            sleep(60 * 60 * 24)
    except (KeyboardInterrupt, SystemExit):
        sys.exit(0)