Пример #1
0
def setup_app(command, conf, vars):
    """Place any commands to setup rdfdatabank here"""
    load_environment(conf.global_conf, conf.local_conf)
    log.info("Creating tables")
    meta.metadata.create_all(bind=meta.engine)
    log.info("Successfully setup")
 
    try:
        g0a = Group()
        g0a.group_name = u'databank_administrator'
        g0a.silo = u'*'
        meta.Session.add(g0a)
        """
        g1a = Group()
        g1a.group_name = u'sandbox_administrator'
        g1a.silo = u'sandbox'
        meta.Session.add(g1a)

        g1b = Group()
        g1b.group_name = u'sandbox_manager'
        g1b.silo = u'sandbox'
        meta.Session.add(g1b)

        g1c = Group()
        g1c.group_name = u'sandbox_submitter'
        g1c.silo = u'sandbox'
        meta.Session.add(g1c)

        g2a = Group()
        g2a.group_name = u'sandbox2_administrator'
        g2a.silo = u'sandbox2'
        meta.Session.add(g2a)

        g2b = Group()
        g2b.group_name = u'sandbox2_manager'
        g2b.silo = u'sandbox2'
        meta.Session.add(g2b)

        g2c = Group()
        g2c.group_name = u'sandbox2_submitter'
        g2c.silo = u'sandbox2'
        meta.Session.add(g2c)

        g3a = Group()
        g3a.group_name = u'sandbox3_administrator'
        g3a.silo = u'sandbox3'
        meta.Session.add(g3a)

        g3b = Group()
        g3b.group_name = u'sandbox3_manager'
        g3b.silo = u'sandbox3'
        meta.Session.add(g3b)

        g3c = Group()
        g3c.group_name = u'sandbox3_submitter'
        g3c.silo = u'sandbox3'
        meta.Session.add(g3c)
        """
        p1 = Permission()
        p1.permission_name = u'administrator'
        p1.groups.append(g0a)
        #p1.groups.append(g1a)
        #p1.groups.append(g2a)
        #p1.groups.append(g3a)
        meta.Session.add(p1)
 
        p2 = Permission()
        p2.permission_name = u'manager'
        #p2.groups.append(g1b)
        #p2.groups.append(g2b)
        #p2.groups.append(g3b)
        meta.Session.add(p2)
 
        p3 = Permission()
        p3.permission_name = u'submitter'
        #p3.groups.append(g1c)
        #p3.groups.append(g2c)
        #p3.groups.append(g3c)
        meta.Session.add(p3)
        """
        u0 = User()
        u0.user_name = u'admin'
        u0.name = u'Databank Administrator'
        u0._set_password(u'test')
        u0.groups.append(g0a)
        meta.Session.add(u0)
 
        u1 = User()
        u1.user_name = u'sandbox_user'
        u1.name = u'Test User I'
        u1._set_password(u'sandbox')
        u1.groups.append(g1c)
        meta.Session.add(u1) 

        u2 = User()
        u2.user_name = u'sandbox_user2'
        u2.name = u'Test User II'
        u2._set_password(u'sandbox2')
        u2.groups.append(g2c)
        meta.Session.add(u2) 

        u3 = User()
        u3.user_name = u'sandbox_user3'
        u3.name = u'Test User III'
        u3._set_password(u'sandbox3')
        u3.groups.append(g3c)
        meta.Session.add(u3) 

        u4 = User()
        u4.user_name = u'admin1'
        u4.name = u'Test Administrator I'
        u4._set_password(u'test')
        u4.groups.append(g1a)
        meta.Session.add(u4)
 
        u5 = User()
        u5.user_name = u'admin2'
        u5.name = u'Test Administrator II'
        u5._set_password(u'test2')
        u5.groups.append(g2a)
        meta.Session.add(u5)
 
        u6 = User()
        u6.user_name = u'admin3'
        u6.name = u'Test Administrator III'
        u6._set_password(u'test3')
        u6.groups.append(g3a)
        meta.Session.add(u6)
 
        u7 = User()
        u7.user_name = u'sandbox_manager'
        u7.name = u'Test Manager I'
        u7._set_password(u'managertest')
        u7.groups.append(g1b)
        meta.Session.add(u7)
 
        u8 = User()
        u8.user_name = u'sandbox_manager2'
        u8.name = u'Test Manager II'
        u8._set_password(u'managertest2')
        u8.groups.append(g2b)
        meta.Session.add(u8)
 
        u9 = User()
        u9.user_name = u'sandbox_manager3'
        u9.name = u'Test Manager III'
        u9._set_password(u'managertest3')
        u9.groups.append(g3b)
        meta.Session.add(u9)
        """
        meta.Session.flush()
        meta.Session.commit()
    except IntegrityError:
        log.error('there was a problem adding your auth data, it may have already been added. Continuing with bootstrapping...')
        #import traceback
        #print traceback.format_exc()
        meta.Session.rollback()
Пример #2
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    #app = httpexceptions.make_middleware(app, global_conf)
    #if asbool(config['debug']):
    #    from repoze.profile.profiler import AccumulatingProfileMiddleware
    #    app = AccumulatingProfileMiddleware(
    #       app,
    #       log_filename=app_conf['profile.log_filename'],
    #       discard_first_request=True,
    #       flush_at_shutdown=True,
    #       path=app_conf['profile.path']
    #       )

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])
    app = SessionMiddleware(app, config)
    app = CacheMiddleware(app, config)

    #TODO: Check if the new error controller works with sword server
    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        if asbool(config['debug']):
            app = StatusCodeRedirect(app)
        else:
            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
    
    app = make_who_with_config(app, global_conf, app_conf['who.config_file'], app_conf['who.log_file'], app_conf['who.log_level'])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])

    return app