diff pics2/pics_test_server.py @ 56:0249782e231e

pics2: add np_keys and selected thumbnail anchoring
author paulo
date Tue, 10 Sep 2013 01:04:24 -0700
parents f5c2934a1e3f
children b7966ae653f2
line diff
     1.1 --- a/pics2/pics_test_server.py	Thu Aug 22 23:53:56 2013 -0700
     1.2 +++ b/pics2/pics_test_server.py	Tue Sep 10 01:04:24 2013 -0700
     1.3 @@ -1,14 +1,38 @@
     1.4 -import wsgiref.simple_server 
     1.5 -import SocketServer
     1.6 +import os
     1.7 +import sys
     1.8 +import signal
     1.9 +
    1.10 +import cherrypy
    1.11 +from cherrypy import wsgiserver
    1.12  
    1.13  import pics_app
    1.14  
    1.15  
    1.16 -class ThreadingWSGIServer(SocketServer.ThreadingMixIn, wsgiref.simple_server.WSGIServer):
    1.17 -	pass
    1.18 +def sighandler(signum, frame):
    1.19 +	sys.stderr.write("Caught signal: %s \n" % signum)
    1.20 +	server.stop()
    1.21 +
    1.22 +
    1.23 +class FileServerRoot:
    1.24 +	def default(self, *args):
    1.25 +		if len(args) == 0:
    1.26 +			raise cherrypy.HTTPError(404)
    1.27 +
    1.28 +		filepath = os.path.abspath(os.path.join(*args))
    1.29 +		return cherrypy.lib.static.serve_file(filepath)
    1.30 +
    1.31 +	default.exposed = True
    1.32  
    1.33  
    1.34  if __name__ == "__main__":
    1.35 -	httpd = ThreadingWSGIServer(('', 8000), wsgiref.simple_server.WSGIRequestHandler)
    1.36 -	httpd.set_app(pics_app.app)
    1.37 -	httpd.serve_forever()
    1.38 +	fileServerApp = cherrypy.Application(FileServerRoot())
    1.39 +	dispatcher = wsgiserver.WSGIPathInfoDispatcher({
    1.40 +		"/pics.fcgi": pics_app.app,
    1.41 +		"": fileServerApp,
    1.42 +	})
    1.43 +	server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher)
    1.44 +
    1.45 +	signal.signal(signal.SIGINT, sighandler)
    1.46 +	signal.signal(signal.SIGTERM, sighandler)
    1.47 +
    1.48 +	server.start()