Source

MyIOTest / myiotest / __init__.py

The default branch has multiple heads

Full commit
from pyramid.config import Configurator
from pyramid_beaker import session_factory_from_settings
from sqlalchemy import engine_from_config
from stargate import is_websocket
import eventlet
from eventlet import wsgi

from myiotest.views import Root
from myiotest.views import Job
from myiotest.views import myJobRoot as jobroot

from myiotest.models import initialize_sql

root = Root()
def root_factory(request):
    return root

#jobroot = JobRoot()
def job_factory(request):
    print "some one call job_factory", request.matchdict.get(u'id')
    print "l'id du jobroot", id(jobroot)
    return jobroot[int(request.matchdict[u'id'])]

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    initialize_sql(engine)
    session_factory = session_factory_from_settings(settings)

    config = Configurator(settings=settings, root_factory=root_factory)
    config.set_session_factory(session_factory)

    config.add_static_view('static', 'myiotest:static', cache_max_age=3600)

    config.add_route('home', '/')
    config.add_route('jobview', '/jobs/{id}', custom_predicates=[is_websocket], factory=job_factory)
    config.add_route('control', '/jobs/{id}', factory=job_factory)

    config.scan()
    app = config.make_wsgi_app()
    listener = eventlet.listen(('127.0.0.1', 9998))
    wsgi.server(listener, app)
   
    return app