rouse/debug.py

44 lines
1.2 KiB
Python

from __future__ import unicode_literals
import gunicorn.app.base
import os
import webob.static
import logging
config = os.path.join(os.path.dirname(__file__), 'development.ini')
class DebugApplication(object):
def __init__(self, app, staticpath='.'):
self.app = app
self.static = webob.static.DirectoryApp(os.path.realpath(staticpath))
def __call__(self, environ, start_response):
if os.path.exists(environ['PATH_INFO'].lstrip('/')):
return self.static(environ, start_response)
else:
return self.app(environ, start_response)
class Server(gunicorn.app.base.BaseApplication):
def load_config(self):
self.cfg.set('bind', '[::]:8080')
self.cfg.set('reload', True)
self.cfg.set('workers', 1)
self.cfg.set('threads', 1)
self.cfg.set('accesslog', '-')
self.cfg.set('timeout', 9001)
def load(self):
import rouse.web
app = rouse.web.Application.create(config)
return DebugApplication(app)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('sqlalchemy.engine.base.Engine').propagate = False
Server().run()