OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 | |
3 # Copyright 2016 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 import argparse | |
8 import os | |
9 import subprocess | |
10 import sys | |
11 import tempfile | |
12 | |
13 LIGHTTPD_CONF = """ | |
14 server.document-root = "{root}" | |
15 server.port = {port} | |
16 mimetype.assign = ( | |
17 ".html" => "text/html" | |
18 ) | |
19 """ | |
20 | |
21 def run_lighttpd(conf): | |
22 """Run lighttpd in a subprocess and block until it exits. | |
23 | |
24 Takes the lighttpd configuration file as a string. | |
25 """ | |
26 with tempfile.NamedTemporaryFile() as conf_file: | |
27 conf_file.write(conf) | |
28 conf_file.file.close() | |
29 server = subprocess.Popen(['lighttpd', '-D', '-f', conf_file.name]) | |
30 try: | |
31 server.wait() | |
32 except KeyboardInterrupt: | |
33 # Let lighttpd handle the signal. | |
34 server.wait() | |
35 | |
36 def main(): | |
37 script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) | |
38 data_dir = os.path.join(script_dir, 'data') | |
39 | |
40 parser = argparse.ArgumentParser() | |
41 parser.add_argument('-p', '--port', default=3000) | |
42 args = parser.parse_args() | |
43 | |
44 conf = LIGHTTPD_CONF.format(port=args.port, root=data_dir) | |
45 print conf | |
46 run_lighttpd(conf) | |
47 | |
48 if __name__ == '__main__': | |
49 main() | |
OLD | NEW |