diff laterlinks2/test_server.py @ 60:9d3a95d80def

add laterlinks2
author paulo
date Fri, 18 Jul 2014 00:47:15 -0700
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/laterlinks2/test_server.py	Fri Jul 18 00:47:15 2014 -0700
     1.3 @@ -0,0 +1,38 @@
     1.4 +import os
     1.5 +import sys
     1.6 +import signal
     1.7 +
     1.8 +import cherrypy
     1.9 +from cherrypy import wsgiserver
    1.10 +
    1.11 +import laterlinks_app
    1.12 +
    1.13 +
    1.14 +def sighandler(signum, frame):
    1.15 +	sys.stderr.write("Caught signal: %s \n" % signum)
    1.16 +	server.stop()
    1.17 +
    1.18 +
    1.19 +class FileServerRoot:
    1.20 +	def default(self, *args):
    1.21 +		if len(args) == 0:
    1.22 +			raise cherrypy.HTTPError(404)
    1.23 +
    1.24 +		filepath = os.path.abspath(os.path.join(*args))
    1.25 +		return cherrypy.lib.static.serve_file(filepath)
    1.26 +
    1.27 +	default.exposed = True
    1.28 +
    1.29 +
    1.30 +if __name__ == "__main__":
    1.31 +	fileServerApp = cherrypy.Application(FileServerRoot())
    1.32 +	dispatcher = wsgiserver.WSGIPathInfoDispatcher({
    1.33 +		"/index.fcgi": laterlinks_app.app,
    1.34 +		"": fileServerApp,
    1.35 +	})
    1.36 +	server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher)
    1.37 +
    1.38 +	signal.signal(signal.SIGINT, sighandler)
    1.39 +	signal.signal(signal.SIGTERM, sighandler)
    1.40 +
    1.41 +	server.start()