annotate pics2/pics_test_server.py @ 124:9b57b90aea31
initial add for pics3
author |
paulo |
date |
Thu, 25 Mar 2021 00:33:42 -0700 |
parents |
0249782e231e |
children |
|
rev |
line source |
paulo@56
|
1 import os
|
paulo@56
|
2 import sys
|
paulo@56
|
3 import signal
|
paulo@56
|
4
|
paulo@56
|
5 import cherrypy
|
paulo@56
|
6 from cherrypy import wsgiserver
|
paulo@52
|
7
|
paulo@52
|
8 import pics_app
|
paulo@52
|
9
|
paulo@52
|
10
|
paulo@56
|
11 def sighandler(signum, frame):
|
paulo@56
|
12 sys.stderr.write("Caught signal: %s \n" % signum)
|
paulo@56
|
13 server.stop()
|
paulo@56
|
14
|
paulo@56
|
15
|
paulo@57
|
16 MIMETYPE = {
|
paulo@57
|
17 ".webm": "video/webm",
|
paulo@57
|
18 }
|
paulo@57
|
19
|
paulo@57
|
20
|
paulo@56
|
21 class FileServerRoot:
|
paulo@56
|
22 def default(self, *args):
|
paulo@56
|
23 if len(args) == 0:
|
paulo@56
|
24 raise cherrypy.HTTPError(404)
|
paulo@56
|
25
|
paulo@56
|
26 filepath = os.path.abspath(os.path.join(*args))
|
paulo@57
|
27 ext = os.path.splitext(filepath)[1]
|
paulo@57
|
28 return cherrypy.lib.static.serve_file(filepath, content_type=MIMETYPE.get(ext))
|
paulo@56
|
29
|
paulo@56
|
30 default.exposed = True
|
paulo@52
|
31
|
paulo@52
|
32
|
paulo@52
|
33 if __name__ == "__main__":
|
paulo@56
|
34 fileServerApp = cherrypy.Application(FileServerRoot())
|
paulo@56
|
35 dispatcher = wsgiserver.WSGIPathInfoDispatcher({
|
paulo@56
|
36 "/pics.fcgi": pics_app.app,
|
paulo@56
|
37 "": fileServerApp,
|
paulo@56
|
38 })
|
paulo@56
|
39 server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher)
|
paulo@56
|
40
|
paulo@56
|
41 signal.signal(signal.SIGINT, sighandler)
|
paulo@56
|
42 signal.signal(signal.SIGTERM, sighandler)
|
paulo@56
|
43
|
paulo@56
|
44 server.start()
|