mirror of
https://github.com/djohnlewis/stackdump
synced 2025-12-06 16:03:27 +00:00
Initial commit. Still building up the env and some parsing code.
This commit is contained in:
31
python/src/servers.py
Normal file
31
python/src/servers.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from bottle import ServerAdapter
|
||||
import sys
|
||||
|
||||
class CherryPyServer(ServerAdapter):
|
||||
'''
|
||||
This copy of bottle's CherryPyServer is necessary so we can set the nodelay
|
||||
option to false when running under Jython. Otherwise it will error out as
|
||||
the TCP_NODELAY option is not supported with Jython.
|
||||
'''
|
||||
|
||||
def run(self, handler): # pragma: no cover
|
||||
from cherrypy import wsgiserver
|
||||
server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
|
||||
|
||||
# Jython doesn't work with the TCP_NODELAY option
|
||||
if sys.platform.startswith('java'):
|
||||
server.nodelay = False
|
||||
|
||||
try:
|
||||
server.start()
|
||||
finally:
|
||||
server.stop()
|
||||
|
||||
# in order for these to be specified in settings.py, they need to be in the
|
||||
# following dictionary.
|
||||
#
|
||||
# if the name clashes with the default bottle ones, they definition here will
|
||||
# be used instead.
|
||||
definitions = {
|
||||
'cherrypy' : CherryPyServer
|
||||
}
|
||||
9
python/src/settings.py
Normal file
9
python/src/settings.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# This is the settings file for stackdump.
|
||||
#
|
||||
# It is modelled after the Django settings file. This file is just like any
|
||||
# other Python file, except the local variables form the settings dictionary.
|
||||
|
||||
# see http://bottlepy.org/docs/dev/tutorial.html#multi-threaded-server
|
||||
SERVER_ADAPTER = 'cherrypy'
|
||||
SERVER_HOST = '0.0.0.0'
|
||||
SERVER_PORT = 8080
|
||||
34
python/src/stackdump.py
Normal file
34
python/src/stackdump.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from bottle import route, run
|
||||
import servers
|
||||
import sys
|
||||
|
||||
# WEB REQUEST METHODS
|
||||
|
||||
@route('/hello')
|
||||
def hello():
|
||||
return "Hello World!"
|
||||
|
||||
# END WEB REQUEST METHODS
|
||||
|
||||
# INITIALISATION
|
||||
|
||||
# load the settings file
|
||||
__import__('settings')
|
||||
if 'settings' in sys.modules.keys():
|
||||
settings = sys.modules.get('settings')
|
||||
settings = dict([ (k, getattr(settings, k)) for k in dir(settings) if not k.startswith('__') ])
|
||||
else:
|
||||
settings = { }
|
||||
|
||||
# run the server!
|
||||
server = settings.get('SERVER_ADAPTER', 'wsgiref')
|
||||
# look for definitions in server, otherwise let bottle decide
|
||||
server = servers.definitions.get(server, server)
|
||||
|
||||
run(
|
||||
server=server,
|
||||
host=settings.get('SERVER_HOST', '0.0.0.0'),
|
||||
port=settings.get('SERVER_PORT', 8080)
|
||||
)
|
||||
|
||||
# END INITIALISATION
|
||||
Reference in New Issue
Block a user