예제 #1
0
    def handle_options(cls, options):
        if not options.extract and not options.load:
            # if action doesn't specified - do both
            options.extract = True
            options.load = True

        if not options.dump_dir:
            if options.load and not options.extract:
                raise ValueError('You must specify directory containing dump files')
            else:
                options.dump_dir = tempfile.mkdtemp()
                log.info("Writing temp files to %s", options.dump_dir)

        if options.load and (not options.project or not options.nbhd):
            raise ValueError('You must specify neighborhood and project '
                                  'to load data')

        if options.extract:
            if options.db_config_prefix:
                for k, v in h.config_with_prefix(config, options.db_config_prefix).iteritems():
                    if k == 'port':
                        v = int(v)
                    setattr(options, k, v)

            if options.source == 'mysql':
                pass
            elif options.source in ('sqlite', 'postgres', 'sql-dump'):
                raise ValueError('This source not implemented yet. Only mysql for now')
            else:
                raise ValueError('You must specify a valid data source')

            if not options.attachments_dir:
                raise ValueError('You must specify path to directory with mediawiki attachmets dump.')

        return options
예제 #2
0
def main():
    sfx.middleware.configure_databases(h.config_with_prefix(config, 'sfx.'))
    topic_trove = T.trove_cat.select(T.trove_cat.c.shortname=='topic').execute().fetchone()
    M.ProjectCategory.query.remove()
    for t in T.trove_cat.select(
        T.trove_cat.c.parent==topic_trove.trove_cat_id).execute():
        parent = M.ProjectCategory(name=t.shortname, label=t.fullname, description=t.description)
        for tt in T.trove_cat.select(
            T.trove_cat.c.parent==t.trove_cat_id).execute():
            M.ProjectCategory(parent_id=parent._id,
                              name=tt.shortname, label=tt.fullname, description=tt.description)
    session(M.ProjectCategory).flush()
예제 #3
0
def main():
    sfx.middleware.configure_databases(h.config_with_prefix(config, 'sfx.'))
    parent_only_troves = T.trove_cat.select(T.trove_cat.c.parent_only==1).execute()
    parent_only_ids = [t.trove_cat_id for t in parent_only_troves]
    allura_troves = M.TroveCategory.query.find(dict(
        trove_cat_id={'$in': parent_only_ids})).all()
    print 'Found %s parent-only troves in alexandria.' % len(parent_only_ids)
    print 'Setting parent-only Allura troves...'
    for t in allura_troves:
        print ' %s: %s' % (t.trove_cat_id, t.fullpath)
        t.parent_only = True
    print 'Updated %s Allura troves.' % len(allura_troves)
    ThreadLocalORMSession.flush_all()
예제 #4
0
def main():
    sfx.middleware.configure_databases(h.config_with_prefix(config, 'sfx.'))
    parent_only_troves = T.trove_cat.select(
        T.trove_cat.c.parent_only == 1).execute()
    parent_only_ids = [t.trove_cat_id for t in parent_only_troves]
    allura_troves = M.TroveCategory.query.find(
        dict(trove_cat_id={'$in': parent_only_ids})).all()
    print 'Found %s parent-only troves in alexandria.' % len(parent_only_ids)
    print 'Setting parent-only Allura troves...'
    for t in allura_troves:
        print ' %s: %s' % (t.trove_cat_id, t.fullpath)
        t.parent_only = True
    print 'Updated %s Allura troves.' % len(allura_troves)
    ThreadLocalORMSession.flush_all()
def main():
    sfx.middleware.configure_databases(h.config_with_prefix(config, 'sfx.'))
    topic_trove = T.trove_cat.select(
        T.trove_cat.c.shortname == 'topic').execute().fetchone()
    M.ProjectCategory.query.remove()
    for t in T.trove_cat.select(
            T.trove_cat.c.parent == topic_trove.trove_cat_id).execute():
        parent = M.ProjectCategory(name=t.shortname,
                                   label=t.fullname,
                                   description=t.description)
        for tt in T.trove_cat.select(
                T.trove_cat.c.parent == t.trove_cat_id).execute():
            M.ProjectCategory(parent_id=parent._id,
                              name=tt.shortname,
                              label=tt.fullname,
                              description=tt.description)
    session(M.ProjectCategory).flush()
예제 #6
0
    def handle_options(cls, options):
        if not options.extract and not options.load:
            # if action doesn't specified - do both
            options.extract = True
            options.load = True

        if not options.dump_dir:
            if options.load and not options.extract:
                raise ValueError(
                    'You must specify directory containing dump files')
            else:
                options.dump_dir = tempfile.mkdtemp()
                log.info("Writing temp files to %s", options.dump_dir)

        if options.load and (not options.project or not options.nbhd):
            raise ValueError('You must specify neighborhood and project '
                             'to load data')

        if options.extract:
            if options.db_config_prefix:
                for k, v in h.config_with_prefix(
                        config, options.db_config_prefix).iteritems():
                    if k == 'port':
                        v = int(v)
                    setattr(options, k, v)

            if options.source == 'mysql':
                pass
            elif options.source in ('sqlite', 'postgres', 'sql-dump'):
                raise ValueError(
                    'This source not implemented yet. Only mysql for now')
            else:
                raise ValueError('You must specify a valid data source')

            if not options.attachments_dir:
                raise ValueError(
                    'You must specify path to directory with mediawiki attachmets dump.'
                )

        return options
예제 #7
0
def _make_core_app(root, global_conf, full_stack=True, **app_conf):
    """
    Set allura up with the settings found in the PasteDeploy configuration
    file used.

    :param root: The controller module containing the TG root
    :param global_conf: The global settings for allura (those
        defined under the ``[DEFAULT]`` section).
    :type global_conf: dict
    :param full_stack: Should the whole TG2 stack be set up?
    :type full_stack: str or bool
    :return: The allura application with all the relevant middleware
        loaded.

    This is the PasteDeploy factory for the allura application.

    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.


    """
    # Run all the initialization code here
    mimetypes.init([pkg_resources.resource_filename("allura", "etc/mime.types")] + mimetypes.knownfiles)
    patches.apply()
    # Configure MongoDB
    ming.configure(**app_conf)

    # Configure ActivityStream
    activitystream.configure(**app_conf)

    # Configure EW variable provider
    ew.render.TemplateEngine.register_variable_provider(get_tg_vars)

    # Create base app
    base_config = ForgeConfig(root)
    load_environment = base_config.make_load_environment()

    # Code adapted from tg.configuration, replacing the following lines:
    #     make_base_app = base_config.setup_tg_wsgi_app(load_environment)
    #     app = make_base_app(global_conf, full_stack=True, **app_conf)

    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    if config.get("zarkov.host"):
        try:
            import zmq
        except ImportError:
            raise ImportError, "Unable to import the zmq library. Please" " check that zeromq is installed or comment out" " the zarkov.host setting in your ini file."

    app = tg.TGApp()
    if asbool(config.get("auth.method", "local") == "sfx"):
        import sfx.middleware

        d = h.config_with_prefix(config, "auth.")
        d.update(h.config_with_prefix(config, "sfx."))
        app = sfx.middleware.SfxMiddleware(app, d)
    # Required for pylons
    app = RoutesMiddleware(app, config["routes.map"])
    # Required for sessions
    app = SessionMiddleware(app, config)
    # Converts exceptions to HTTP errors, shows traceback in debug mode
    app = tg.error.ErrorHandler(app, global_conf, **config["pylons.errorware"])
    # Redirect some status codes to /error/document
    if asbool(config["debug"]):
        app = StatusCodeRedirect(app, base_config.handle_status_codes)
    else:
        app = StatusCodeRedirect(app, base_config.handle_status_codes + [500])
    # Redirect 401 to the login page
    app = LoginRedirectMiddleware(app)
    # Add instrumentation
    app = AlluraTimerMiddleware(app, app_conf)
    # Clear cookies when the CSRF field isn't posted
    if not app_conf.get("disable_csrf_protection"):
        app = CSRFMiddleware(app, "_session_id")
    # Setup the allura SOPs
    app = allura_globals_middleware(app)
    # Ensure https for logged in users, http for anonymous ones
    if asbool(app_conf.get("auth.method", "local") == "sfx"):
        app = SSLMiddleware(app, app_conf.get("no_redirect.pattern"))
    # Setup resource manager, widget context SOP
    app = ew.WidgetMiddleware(
        app,
        compress=not asbool(global_conf["debug"]),
        # compress=True,
        script_name=app_conf.get("ew.script_name", "/_ew_resources/"),
        url_base=app_conf.get("ew.url_base", "/_ew_resources/"),
        extra_headers=eval(app_conf.get("ew.extra_headers", "None")),
    )
    # Make sure that the wsgi.scheme is set appropriately when we
    # have the funky HTTP_X_SFINC_SSL  environ var
    if asbool(app_conf.get("auth.method", "local") == "sfx"):
        app = set_scheme_middleware(app)
    # Handle static files (by tool)
    app = StaticFilesMiddleware(app, app_conf.get("static.script_name"))
    # Handle setup and flushing of Ming ORM sessions
    app = MingMiddleware(app)
    # Set up the registry for stacked object proxies (SOPs).
    #    streaming=true ensures they won't be cleaned up till
    #    the WSGI application's iterator is exhausted
    app = RegistryManager(app, streaming=True)
    return app
예제 #8
0
def _make_core_app(root, global_conf, full_stack=True, **app_conf):
    """
    Set allura up with the settings found in the PasteDeploy configuration
    file used.

    :param root: The controller module containing the TG root
    :param global_conf: The global settings for allura (those
        defined under the ``[DEFAULT]`` section).
    :type global_conf: dict
    :param full_stack: Should the whole TG2 stack be set up?
    :type full_stack: str or bool
    :return: The allura application with all the relevant middleware
        loaded.

    This is the PasteDeploy factory for the allura application.

    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.


    """
    # Run all the initialization code here
    mimetypes.init(
        [pkg_resources.resource_filename('allura', 'etc/mime.types')]
        + mimetypes.knownfiles)
    patches.apply()
    try:
        import newrelic
    except ImportError:
        pass
    else:
        patches.newrelic()
    # Configure MongoDB
    ming.configure(**app_conf)

    # Configure ActivityStream
    if asbool(app_conf.get('activitystream.recording.enabled', False)):
        activitystream.configure(**app_conf)

    # Configure EW variable provider
    ew.render.TemplateEngine.register_variable_provider(get_tg_vars)
    
    # Set FormEncode language to english, as we don't support any other locales
    formencode.api.set_stdtranslation(domain='FormEncode', languages=['en'])

    # Create base app
    base_config = ForgeConfig(root)
    load_environment = base_config.make_load_environment()

    # Code adapted from tg.configuration, replacing the following lines:
    #     make_base_app = base_config.setup_tg_wsgi_app(load_environment)
    #     app = make_base_app(global_conf, full_stack=True, **app_conf)

    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    if config.get('zarkov.host'):
        try:
            import zmq
        except ImportError:
            raise ImportError, "Unable to import the zmq library. Please"\
                               " check that zeromq is installed or comment out"\
                               " the zarkov.host setting in your ini file."

    app = tg.TGApp()
    if asbool(config.get('auth.method', 'local')=='sfx'):
        import sfx.middleware
        d = h.config_with_prefix(config, 'auth.')
        d.update(h.config_with_prefix(config, 'sfx.'))
        app = sfx.middleware.SfxMiddleware(app, d)
    # Required for pylons
    app = RoutesMiddleware(app, config['routes.map'])
    # Required for sessions
    app = SessionMiddleware(app, config)
    # Redirect 401 to the login page
    app = LoginRedirectMiddleware(app)
    # Add instrumentation
    app = AlluraTimerMiddleware(app, app_conf)
    # Clear cookies when the CSRF field isn't posted
    if not app_conf.get('disable_csrf_protection'):
        app = CSRFMiddleware(app, '_session_id')
    # Setup the allura SOPs
    app = allura_globals_middleware(app)
    # Ensure https for logged in users, http for anonymous ones
    if asbool(app_conf.get('auth.method', 'local')=='sfx'):
        app = SSLMiddleware(app, app_conf.get('no_redirect.pattern'))
    # Setup resource manager, widget context SOP
    app = ew.WidgetMiddleware(
        app,
        compress=not asbool(global_conf['debug']),
        # compress=True,
        script_name=app_conf.get('ew.script_name', '/_ew_resources/'),
        url_base=app_conf.get('ew.url_base', '/_ew_resources/'),
        extra_headers=eval(app_conf.get('ew.extra_headers', 'None')))
    # Handle static files (by tool)
    app = StaticFilesMiddleware(app, app_conf.get('static.script_name'))
    # Handle setup and flushing of Ming ORM sessions
    app = MingMiddleware(app)
    # Set up the registry for stacked object proxies (SOPs).
    #    streaming=true ensures they won't be cleaned up till
    #    the WSGI application's iterator is exhausted
    app = RegistryManager(app, streaming=True)
    # Converts exceptions to HTTP errors, shows traceback in debug mode
    tg.error.footer_html = '<!-- %s %s -->'  # don't use TG footer with extra CSS & images that take time to load
    app = tg.error.ErrorHandler(app, global_conf, **config['pylons.errorware'])
    # Make sure that the wsgi.scheme is set appropriately when we
    # have the funky HTTP_X_SFINC_SSL  environ var
    if asbool(app_conf.get('auth.method', 'local')=='sfx'):
        app = set_scheme_middleware(app)
    # Redirect some status codes to /error/document
    if config.get('override_root') != 'task':
        # "task" wsgi would get a 2nd request to /error/document if we used this middleware
        if asbool(config['debug']):
            app = StatusCodeRedirect(app, base_config.handle_status_codes)
        else:
            app = StatusCodeRedirect(app, base_config.handle_status_codes + [500])
    return app