# Path: pyas2/pyas2init.py
# def initialize():
# def initserverlogging(logname):


from django.core.management.base import BaseCommand
from django.core.handlers.wsgi import WSGIHandler
from django.utils.translation import ugettext as _
from pyas2 import pyas2init
            from cherrypy import wsgiserver
import pyas2
import os
            import cherrypy
        # but django does not need the AdminMediaHandler in this setup. is much faster.
        servedjango = WSGIHandler()

        # cherrypy uses a dispatcher in order to handle the serving of
        # static files and django.
        dispatcher = wsgiserver.WSGIPathInfoDispatcher(
            {'/': servedjango, '/static': servestaticfiles})

        pyas2server = wsgiserver.CherryPyWSGIServer(
            bind_addr=('0.0.0.0', pyas2init.gsettings['port']),
            wsgi_app=dispatcher,
            server_name='pyas2-webserver'
        )

        pyas2init.logger.log(
            25, _(u'PyAS2 server running at port: "%s".' % pyas2init.gsettings['port']))

        # handle ssl: cherrypy < 3.2 always uses pyOpenssl. cherrypy >= 3.2
        # uses python buildin ssl (python >= 2.6 has buildin support for ssl).
        ssl_certificate = pyas2init.gsettings['ssl_certificate']
        ssl_private_key = pyas2init.gsettings['ssl_private_key']
        if ssl_certificate and ssl_private_key:
            if cherrypy.__version__ >= '3.2.0':
                adapter_class = wsgiserver.get_ssl_adapter_class('builtin')
                pyas2server.ssl_adapter = adapter_class(ssl_certificate, ssl_private_key)
            else:
                # but: pyOpenssl should be there!
                pyas2server.ssl_certificate = ssl_certificate
                pyas2server.ssl_private_key = ssl_private_key
            pyas2init.logger.log(25, _(u'PyAS2 server uses ssl (https).'))

# Path: pyas2/pyas2init.py
# def initialize():
# def initserverlogging(logname):


# Path: pyas2/management/commands/runas2server.py
from django.core.management.base import BaseCommand
from django.core.handlers.wsgi import WSGIHandler
from django.utils.translation import ugettext as _
from pyas2 import pyas2init
            from cherrypy import wsgiserver
import pyas2
import os
            import cherrypy

        # but django does not need the AdminMediaHandler in this setup. is much faster.
        servedjango = WSGIHandler()

        # cherrypy uses a dispatcher in order to handle the serving of
        # static files and django.
        dispatcher = wsgiserver.WSGIPathInfoDispatcher(
            {'/': servedjango, '/static': servestaticfiles})

        pyas2server = wsgiserver.CherryPyWSGIServer(
            bind_addr=('0.0.0.0', pyas2init.gsettings['port']),
            wsgi_app=dispatcher,
            server_name='pyas2-webserver'
        )

        pyas2init.logger.log(
            25, _(u'PyAS2 server running at port: "%s".' % pyas2init.gsettings['port']))

        # handle ssl: cherrypy < 3.2 always uses pyOpenssl. cherrypy >= 3.2
        # uses python buildin ssl (python >= 2.6 has buildin support for ssl).
        ssl_certificate = pyas2init.gsettings['ssl_certificate']
        ssl_private_key = pyas2init.gsettings['ssl_private_key']
        if ssl_certificate and ssl_private_key:
            if cherrypy.__version__ >= '3.2.0':
                adapter_class = wsgiserver.get_ssl_adapter_class('builtin')
                pyas2server.ssl_adapter = adapter_class(ssl_certificate, ssl_private_key)
            else:
                # but: pyOpenssl should be there!
                pyas2server.ssl_certificate = ssl_certificate
                pyas2server.ssl_private_key = ssl_private_key
            pyas2init.logger.log(25, _(u'PyAS2 server uses ssl (https).'))

        else: