2019-02-08 13:57:59 +00:00
|
|
|
"""passbook Webserver management command"""
|
|
|
|
|
2019-07-04 13:23:05 +00:00
|
|
|
import cherrypy
|
|
|
|
from django.conf import settings
|
2019-02-08 13:57:59 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
2019-10-01 08:24:10 +00:00
|
|
|
from structlog import get_logger
|
2019-02-08 13:57:59 +00:00
|
|
|
|
2019-04-11 11:43:49 +00:00
|
|
|
from passbook.lib.config import CONFIG
|
2019-07-04 13:23:05 +00:00
|
|
|
from passbook.root.wsgi import application
|
2019-02-08 13:57:59 +00:00
|
|
|
|
2019-10-01 08:24:10 +00:00
|
|
|
LOGGER = get_logger(__name__)
|
2019-02-08 13:57:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
"""Run CherryPy webserver"""
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2019-07-04 13:23:05 +00:00
|
|
|
"""passbook cherrypy server"""
|
2019-09-30 16:04:04 +00:00
|
|
|
cherrypy.config.update(CONFIG.y('web'))
|
2019-07-04 13:23:05 +00:00
|
|
|
cherrypy.tree.graft(application, '/')
|
|
|
|
# Mount NullObject to serve static files
|
|
|
|
cherrypy.tree.mount(None, settings.STATIC_URL, config={
|
|
|
|
'/': {
|
|
|
|
'tools.staticdir.on': True,
|
|
|
|
'tools.staticdir.dir': settings.STATIC_ROOT,
|
|
|
|
'tools.expires.on': True,
|
|
|
|
'tools.expires.secs': 86400,
|
|
|
|
'tools.gzip.on': True,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
cherrypy.engine.start()
|
|
|
|
for file in CONFIG.loaded_file:
|
|
|
|
cherrypy.engine.autoreload.files.add(file)
|
|
|
|
LOGGER.info("Added '%s' to autoreload triggers", file)
|
|
|
|
cherrypy.engine.block()
|