Beispiel #1
0
    def __init__(self,
                 connection,
                 database_path,
                 public_store,
                 queue_store,
                 staticdirector,
                 user_template_path=None):
        # Get the template environment
        self.template_env = util.get_jinja_env(user_template_path)

        # Set up storage systems
        self.public_store = public_store
        self.queue_store = queue_store

        # Set up database
        self.connection = connection
        self.db = connection[database_path]
        models.register_models(connection)

        # set up routing
        self.routing = routing.get_mapper()

        # set up staticdirector tool
        self.staticdirector = staticdirector

        # certain properties need to be accessed globally eg from
        # validators, etc, which might not access to the request
        # object.
        setup_globals(db_connection=connection,
                      database=self.db,
                      public_store=self.public_store,
                      queue_store=self.queue_store)
Beispiel #2
0
    def __init__(self, connection, database_path,
                 public_store, queue_store,
                 staticdirector,
                 user_template_path=None):
        # Get the template environment
        self.template_env = util.get_jinja_env(user_template_path)
        
        # Set up storage systems
        self.public_store = public_store
        self.queue_store = queue_store

        # Set up database
        self.connection = connection
        self.db = connection[database_path]
        models.register_models(connection)

        # set up routing
        self.routing = routing.get_mapper()

        # set up staticdirector tool
        self.staticdirector = staticdirector

        # certain properties need to be accessed globally eg from
        # validators, etc, which might not access to the request
        # object.
        setup_globals(
            db_connection=connection,
            database=self.db,
            public_store=self.public_store,
            queue_store=self.queue_store)
    def __init__(self, config_path, setup_celery=True):
        """
        Initialize the application based on a configuration file.

        Arguments:
         - config_path: path to the configuration file we're opening.
         - setup_celery: whether or not to setup celery during init.
           (Note: setting 'celery_setup_elsewhere' also disables
           setting up celery.)
        """
        ##############
        # Setup config
        ##############

        # Open and setup the config
        global_config, validation_result = read_mediagoblin_config(config_path)
        app_config = global_config['mediagoblin']
        # report errors if necessary
        validation_report = generate_validation_report(
            global_config, validation_result)
        if validation_report:
            raise ImproperlyConfigured(validation_report)

        ##########################################
        # Setup other connections / useful objects
        ##########################################

        # Set up the database
        self.connection, self.db = setup_connection_and_db_from_config(
            app_config)

        # Get the template environment
        self.template_loader = util.get_jinja_loader(
            app_config.get('user_template_path'))
        
        # Set up storage systems
        self.public_store = storage.storage_system_from_config(
            app_config, 'publicstore')
        self.queue_store = storage.storage_system_from_config(
            app_config, 'queuestore')

        # set up routing
        self.routing = routing.get_mapper()

        # set up staticdirector tool
        if app_config.has_key('direct_remote_path'):
            self.staticdirector = staticdirect.RemoteStaticDirect(
                app_config['direct_remote_path'].strip())
        elif app_config.has_key('direct_remote_paths'):
            direct_remote_path_lines = app_config[
                'direct_remote_paths'].strip().splitlines()
            self.staticdirector = staticdirect.MultiRemoteStaticDirect(
                dict([line.strip().split(' ', 1)
                      for line in direct_remote_path_lines]))
        else:
            raise ImproperlyConfigured(
                "One of direct_remote_path or "
                "direct_remote_paths must be provided")

        # Setup celery, if appropriate
        if setup_celery and not app_config.get('celery_setup_elsewhere'):
            if os.environ.get('CELERY_ALWAYS_EAGER'):
                setup_celery_from_config(
                    app_config, global_config,
                    force_celery_always_eager=True)
            else:
                setup_celery_from_config(app_config, global_config)

        #######################################################
        # Insert appropriate things into mediagoblin.mg_globals
        #
        # certain properties need to be accessed globally eg from
        # validators, etc, which might not access to the request
        # object.
        #######################################################

        setup_globals(
            app_config=app_config,
            global_config=global_config,

            # TODO: No need to set these two up as globals, we could
            # just read them out of mg_globals.app_config
            email_sender_address=app_config['email_sender_address'],
            email_debug_mode=app_config['email_debug_mode'],

            # Actual, useful to everyone objects
            app=self,
            db_connection=self.connection,
            database=self.db,
            public_store=self.public_store,
            queue_store=self.queue_store,
            workbench_manager=WorkbenchManager(app_config['workbench_path']))
Beispiel #4
0
    def __init__(self, config_path, setup_celery=True):
        """
        Initialize the application based on a configuration file.

        Arguments:
         - config_path: path to the configuration file we're opening.
         - setup_celery: whether or not to setup celery during init.
           (Note: setting 'celery_setup_elsewhere' also disables
           setting up celery.)
        """
        ##############
        # Setup config
        ##############

        # Open and setup the config
        global_config, validation_result = read_mediagoblin_config(config_path)
        app_config = global_config['mediagoblin']
        # report errors if necessary
        validation_report = generate_validation_report(global_config,
                                                       validation_result)
        if validation_report:
            raise ImproperlyConfigured(validation_report)

        ##########################################
        # Setup other connections / useful objects
        ##########################################

        # Set up the database
        self.connection, self.db = setup_connection_and_db_from_config(
            app_config)

        # Get the template environment
        self.template_loader = util.get_jinja_loader(
            app_config.get('user_template_path'))

        # Set up storage systems
        self.public_store = storage.storage_system_from_config(
            app_config, 'publicstore')
        self.queue_store = storage.storage_system_from_config(
            app_config, 'queuestore')

        # set up routing
        self.routing = routing.get_mapper()

        # set up staticdirector tool
        if app_config.has_key('direct_remote_path'):
            self.staticdirector = staticdirect.RemoteStaticDirect(
                app_config['direct_remote_path'].strip())
        elif app_config.has_key('direct_remote_paths'):
            direct_remote_path_lines = app_config['direct_remote_paths'].strip(
            ).splitlines()
            self.staticdirector = staticdirect.MultiRemoteStaticDirect(
                dict([
                    line.strip().split(' ', 1)
                    for line in direct_remote_path_lines
                ]))
        else:
            raise ImproperlyConfigured("One of direct_remote_path or "
                                       "direct_remote_paths must be provided")

        # Setup celery, if appropriate
        if setup_celery and not app_config.get('celery_setup_elsewhere'):
            if os.environ.get('CELERY_ALWAYS_EAGER'):
                setup_celery_from_config(app_config,
                                         global_config,
                                         force_celery_always_eager=True)
            else:
                setup_celery_from_config(app_config, global_config)

        #######################################################
        # Insert appropriate things into mediagoblin.mg_globals
        #
        # certain properties need to be accessed globally eg from
        # validators, etc, which might not access to the request
        # object.
        #######################################################

        setup_globals(
            app_config=app_config,
            global_config=global_config,

            # TODO: No need to set these two up as globals, we could
            # just read them out of mg_globals.app_config
            email_sender_address=app_config['email_sender_address'],
            email_debug_mode=app_config['email_debug_mode'],

            # Actual, useful to everyone objects
            app=self,
            db_connection=self.connection,
            database=self.db,
            public_store=self.public_store,
            queue_store=self.queue_store,
            workbench_manager=WorkbenchManager(app_config['workbench_path']))
Beispiel #5
0
    def __init__(self, config_path, setup_celery=True):
        """
        Initialize the application based on a configuration file.

        Arguments:
         - config_path: path to the configuration file we're opening.
         - setup_celery: whether or not to setup celery during init.
           (Note: setting 'celery_setup_elsewhere' also disables
           setting up celery.)
        """
        _log.info("GNU MediaGoblin %s main server starting", __version__)
        _log.debug("Using config file %s", config_path)
        ##############
        # Setup config
        ##############

        # Open and setup the config
        global_config, app_config = setup_global_and_app_config(config_path)

        ##########################################
        # Setup other connections / useful objects
        ##########################################

        # Set up plugins -- need to do this early so that plugins can
        # affect startup.
        _log.info("Setting up plugins.")
        setup_plugins()

        # Set up the database
        self.connection, self.db = setup_database()

        # Register themes
        self.theme_registry, self.current_theme = register_themes(app_config)

        # Get the template environment
        self.template_loader = get_jinja_loader(
            app_config.get('local_templates'),
            self.current_theme,
            PluginManager().get_template_paths()
            )

        # Set up storage systems
        self.public_store, self.queue_store = setup_storage()

        # set up routing
        self.routing = routing.get_mapper(PluginManager().get_routes())

        # set up staticdirector tool
        self.staticdirector = get_staticdirector(app_config)

        # set up caching
        self.cache = setup_beaker_cache()

        # Setup celery, if appropriate
        if setup_celery and not app_config.get('celery_setup_elsewhere'):
            if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true':
                setup_celery_from_config(
                    app_config, global_config,
                    force_celery_always_eager=True)
            else:
                setup_celery_from_config(app_config, global_config)

        #######################################################
        # Insert appropriate things into mediagoblin.mg_globals
        #
        # certain properties need to be accessed globally eg from
        # validators, etc, which might not access to the request
        # object.
        #######################################################

        setup_globals(app=self)

        # Workbench *currently* only used by celery, so this only
        # matters in always eager mode :)
        setup_workbench()

        # instantiate application meddleware
        self.meddleware = [common.import_component(m)(self)
                           for m in meddleware.ENABLED_MEDDLEWARE]