'When the bus starts, the plugin is also started
and we load the Django application. We then mount it on
the CherryPy engine for serving as a WSGI application.
We let CherryPy serve the application\'s static files.'

def start(self):

    cherrypy.log('Loading    and    serving    the    Django    application')
    cherrypy.tree.graft(WSGIHandler())
    if getattr(settings, 'CONTENT_ROOT', None):
        from kalite.contentload.settings import ASSESSMENT_ITEM_ROOT
        static_handler = cherrypy.tools.staticdir.handler(section='/', dir='', root=os.path.abspath(ASSESSMENT_ITEM_ROOT), content_types=WELL_KNOWN_CONTENT_TYPES)
        cherrypy.tree.mount(static_handler, (settings.CONTENT_URL + 'assessment/'))
        static_handler = cherrypy.tools.staticdir.handler(section='/', dir=os.path.split(settings.CONTENT_ROOT)[1], root=os.path.abspath(os.path.split(settings.CONTENT_ROOT)[0]), content_types=WELL_KNOWN_CONTENT_TYPES)
        cherrypy.tree.mount(static_handler, settings.CONTENT_URL)
    static_handler = cherrypy.tools.staticdir.handler(section='/', dir=os.path.split(settings.MEDIA_ROOT)[1], root=os.path.abspath(os.path.split(settings.MEDIA_ROOT)[0]), content_types=WELL_KNOWN_CONTENT_TYPES)
    cherrypy.tree.mount(static_handler, settings.MEDIA_URL)
    static_handler = cherrypy.tools.staticdir.handler(section='/', dir=os.path.split(settings.STATIC_ROOT)[1], root=os.path.abspath(os.path.split(settings.STATIC_ROOT)[0]), content_types=WELL_KNOWN_CONTENT_TYPES)
    cherrypy.tree.mount(static_handler, settings.STATIC_URL)
    admin_static_dir = os.path.join(django.__path__[0], 'contrib', 'admin', 'static')
    admin_static_handler = cherrypy.tools.staticdir.handler(section='/', dir='admin', root=admin_static_dir, content_types=WELL_KNOWN_CONTENT_TYPES)
    cherrypy.tree.mount(admin_static_handler, urlparse.urljoin(settings.STATIC_URL, 'admin'))
