Ejemplo n.º 1
0
def env_import(args):
    '''
    Restore mongo database and media files from a tar archive
    '''
    if not args.cache_path:
        args.cache_path = tempfile.mkdtemp()

    setup_global_and_app_config(args.conf_file)

    # Creates mg_globals.public_store and mg_globals.queue_store
    setup_storage()

    global_config, app_config = setup_global_and_app_config(args.conf_file)
    db = setup_connection_and_db_from_config(
        app_config)

    tf = tarfile.open(
        args.tar_file,
        mode='r|gz')

    tf.extractall(args.cache_path)

    args.cache_path = os.path.join(
        args.cache_path, 'mediagoblin-data')
    args = _setup_paths(args)

    # Import database from extracted data
    _import_database(db, args)

    _import_media(db, args)

    _clean(args)
Ejemplo n.º 2
0
def env_import(args):
    '''
    Restore mongo database and media files from a tar archive
    '''
    if not args.cache_path:
        args.cache_path = tempfile.mkdtemp()

    setup_global_and_app_config(args.conf_file)

    # Creates mg_globals.public_store and mg_globals.queue_store
    setup_storage()

    global_config, app_config = setup_global_and_app_config(args.conf_file)
    db = setup_connection_and_db_from_config(
        app_config)

    tf = tarfile.open(
        args.tar_file,
        mode='r|gz')

    tf.extractall(args.cache_path)

    args.cache_path = os.path.join(
        args.cache_path, 'mediagoblin-data')
    args = _setup_paths(args)

    # Import database from extracted data
    _import_database(db, args)

    _import_media(db, args)

    _clean(args)
Ejemplo n.º 3
0
def env_export(args):
    '''
    Export database and media files to a tar archive
    '''
    if args.cache_path:
        if os.path.exists(args.cache_path):
            _log.error('The cache directory must not exist '
                       'before you run this script')
            _log.error('Cache directory: {0}'.format(args.cache_path))

            return False
    else:
        args.cache_path = tempfile.mkdtemp()

    args = _setup_paths(args)

    if not _export_check(args):
        _log.error('Checks did not pass, exiting')
        sys.exit(0)

    globa_config, app_config = setup_global_and_app_config(args.conf_file)

    setup_storage()

    db = setup_connection_and_db_from_config(app_config)

    _export_database(db, args)

    _export_media(db, args)

    _create_archive(args)

    _clean(args)
Ejemplo n.º 4
0
def assetlink_command(args):
    """
    Link the asset directory of the currently installed theme
    """
    global_config, app_config = setup_global_and_app_config(args.conf_file)
    theme_registry, current_theme = register_themes(app_config)
    link_assets(current_theme, app_config['theme_linked_assets_dir'])
Ejemplo n.º 5
0
def install_command(args):
    """
    Handle the 'install this theme' subcommand
    """
    global_config, app_config = setup_global_and_app_config(args.conf_file)
    install_dir = app_config['theme_install_dir']
    install_theme(install_dir, args.themefile)
Ejemplo n.º 6
0
def env_export(args):
    '''
    Export database and media files to a tar archive
    '''
    commands_util.check_unrecognized_args(args)
    if args.cache_path:
        if os.path.exists(args.cache_path):
            _log.error('The cache directory must not exist '
                       'before you run this script')
            _log.error('Cache directory: {0}'.format(args.cache_path))

            return False
    else:
        args.cache_path = tempfile.mkdtemp()

    args = _setup_paths(args)

    if not _export_check(args):
        _log.error('Checks did not pass, exiting')
        sys.exit(0)

    globa_config, app_config = setup_global_and_app_config(args.conf_file)

    setup_storage()

    db = setup_connection_and_db_from_config(app_config)

    _export_database(db, args)

    _export_media(db, args)

    _create_archive(args)

    _clean(args)
Ejemplo n.º 7
0
def run_migrate(conf_file):
    # This MUST be imported so as to set up the appropriate migrations!
    from mediagoblin.db.mongo import migrations

    from mediagoblin.db.mongo import util as db_util
    from mediagoblin.db.mongo.open import setup_connection_and_db_from_config

    global_config, app_config = setup_global_and_app_config(conf_file)

    connection, db = setup_connection_and_db_from_config(
        app_config, use_pymongo=True)
    migration_manager = db_util.MigrationManager(db)

    # Clear old indexes
    print "== Clearing old indexes... =="
    removed_indexes = db_util.remove_deprecated_indexes(db)

    for collection, index_name in removed_indexes:
        print "Removed index '%s' in collection '%s'" % (
            index_name, collection)

    # Migrate
    print "\n== Applying migrations... =="
    migration_manager.migrate_new(
        pre_callback=_print_started_migration,
        post_callback=_print_finished_migration)

    # Add new indexes
    print "\n== Adding new indexes... =="
    new_indexes = db_util.add_new_indexes(db)

    for collection, index_name in new_indexes:
        print "Added index '%s' to collection '%s'" % (
            index_name, collection)
Ejemplo n.º 8
0
def run_conversion(config_name):
    global_config, app_config = setup_global_and_app_config(config_name)

    sql_conn, sql_db = sql_connect(app_config)
    mk_conn, mk_db = mongo_connect(app_config)

    Base_v0.metadata.create_all(sql_db.engine)

    for title, func in convert_call_list:
        print_header(title)
        func(mk_db)
        Session.remove()
    
    for title, func in sql_call_list:
        print_header(title)
        func(sql_db)
        Session.remove()
Ejemplo n.º 9
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)

        media_type_warning()

        setup_crypto()

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

        # Setup Session Manager, not needed in celery
        self.session_manager = session.SessionManager()

        # load all available locales
        setup_locales()

        # 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.db = setup_database(app_config['run_migrations'])

        # Quit app if need to run dbupdate
        check_db_up_to_date()

        # 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()
            )

        # Check if authentication plugin is enabled and respond accordingly.
        self.auth = check_auth_enabled()
        if not self.auth:
            app_config['allow_comments'] = False

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

        # set up routing
        self.url_map = get_url_map()

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

        # 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]
Ejemplo n.º 10
0
def dbupdate(args):
    global_config, app_config = setup_global_and_app_config(args.conf_file)
    run_dbupdate(app_config, global_config)
Ejemplo n.º 11
0
def dbupdate(args):
    global_config, app_config = setup_global_and_app_config(args.conf_file)
    run_dbupdate(app_config, global_config)
Ejemplo n.º 12
0
def raw_alembic_cli(args):
    global_config, app_config = setup_global_and_app_config(args.conf_file)
    db = setup_connection_and_db_from_config(app_config, migrations=False)
    FudgedCommandLine().main(args, db, global_config)
Ejemplo n.º 13
0
def raw_alembic_cli(args):
    global_config, app_config = setup_global_and_app_config(args.conf_file)
    db = setup_connection_and_db_from_config(app_config, migrations=False)
    FudgedCommandLine().main(args, db, global_config)