Example #1
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    # We import in the main() function to avoid messing with namespace mechanism. We have to avoid
    # any code/import other than the declare_namespace() in a namespace pkg's init. See
    # http://packages.python.org/distribute/setuptools.html#namespace-packages

    # Monkeypatches the xmlrpclib to set partial application of allow_none
    #
    # sflvault relies on a behaviour provided by an older version of pylons_xmlrpc
    # that set the allow_none parameter by default. However, pyramid uses 
    # the new pyramid_rpc module that doesn't set this parameter and does not provide
    # any way of setting it manually.
    #
    xmlrpclib.dumps = functools.partial(xmlrpclib.dumps, allow_none=True)

    from pyramid.config import Configurator
    from sqlalchemy import engine_from_config
    #from controller.xmlrpc import SflVaultController
    from sflvault import model
    from sflvault.model import init_model
    from sflvault.lib.vault import SFLvaultAccess

    from datetime import datetime, timedelta
    import transaction
    print "Global config: %s " % global_config
    print "settings: %s" % settings

    # Configure the Pyramid app and SQL engine
    engine = engine_from_config(settings, 'sqlalchemy.')
    config = Configurator(settings=settings)
    config.include('pyramid_rpc.xmlrpc')
    config.add_xmlrpc_endpoint('sflvault', '/vault/rpc')
    config.scan('sflvault.views')

    # Configures the vault
    if 'sflvault.vault.session_timeout' in settings:
        SFLvaultAccess.session_timeout = settings['sflvault.vault.session_timeout']

    if 'sflvault.vault.setup_timeout' in settings:
        SFLvaultAccess.setup_timeout = settings['sflvault.vault.setup_timeout']


    init_model(engine)
    model.meta.metadata.create_all(engine)
    #Add admin user if not present
    if not model.query(model.User).filter_by(username='******').first():
        log.info ("It seems like you are using SFLvault for the first time. An\
                'admin' user account will be added to the system.")
        u = model.User()
        u.waiting_setup = datetime.now() + timedelta(0,900)
        u.username = u'admin'
        u.created_time = datetime.now()
        u.is_admin = True
        #transaction.begin()
        model.meta.Session.add(u)
        transaction.commit()
        log.info("Added 'admin' user, you have 15 minutes to setup from your client")
    return config.make_wsgi_app()
Example #2
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    # We import in the main() function to avoid messing with namespace mechanism. We have to avoid
    # any code/import other than the declare_namespace() in a namespace pkg's init. See
    # http://packages.python.org/distribute/setuptools.html#namespace-packages
    from pyramid.config import Configurator
    from sqlalchemy import engine_from_config
    #from controller.xmlrpc import SflVaultController
    from sflvault import model
    from sflvault.model import init_model
    from datetime import datetime, timedelta
    import transaction
    print "Global config: %s " % global_config
    print "settings: %s" % settings
    engine = engine_from_config(settings, 'sqlalchemy.')
#    initialize_sql(engine)
    config = Configurator(settings=settings)
    config.include('pyramid_rpc.xmlrpc')
    config.add_xmlrpc_endpoint('sflvault', '/vault/rpc')
    config.scan('sflvault.views')
#    config.add_view(SflVaultController,  route_name='xmlrpcvault')
#    session_factory = session_factory_from_settings(settings)
#    config.set_session_factory(session_factory)

    init_model(engine)
    model.meta.metadata.create_all(engine)
    #Add admin user if not present
    if not model.query(model.User).filter_by(username='******').first():
        log.info ("It seems like you are using SFLvault for the first time. An\
                'admin' user account will be added to the system.")
        u = model.User()
        u.waiting_setup = datetime.now() + timedelta(0,900)
        u.username = u'admin'
        u.created_time = datetime.now()
        u.is_admin = True
        #transaction.begin()
        model.meta.Session.add(u)
        transaction.commit()
        log.info("Added 'admin' user, you have 15 minutes to setup from your client")
    return config.make_wsgi_app()
Example #3
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='sflvault', paths=paths)

    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = sflvault.lib.helpers

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
            directories=paths['templates'],
            error_handler=handle_mako_error,
            module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
            input_encoding='utf-8', output_encoding='utf-8',
            imports=['from webhelpers.html import escape'],
            default_filters=['escape'])

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)
    engine = engine_from_config(config, 'sqlalchemy.')
    init_model(engine)

    mc = pylibmc.Client(
        servers=config['memcache.servers'],
        username=config['memcache.username'],
        password=config['memcache.password'],
        binary=True
    )
    init_mc(mc)