コード例 #1
0
ファイル: main.py プロジェクト: zhanght0311/awd-platform
def upgrade(all_latest, fixture, force):
    """Updates the migrations and fixtures."""
    if all_latest:
        click.secho("[+] Upgrading migrations to the latest version...",
                    fg="cyan")
        alembic.upgrade()

    if fixture or all_latest:
        try:
            settings = import_string("flaskbb.fixtures.{}".format(fixture))
            settings = settings.fixture
        except ImportError:
            raise FlaskBBCLIError(
                "{} fixture is not available".format(fixture), fg="red")

        click.secho("[+] Updating fixtures...", fg="cyan")
        count = update_settings_from_fixture(fixture=settings,
                                             overwrite_group=force,
                                             overwrite_setting=force)
        click.secho("[+] {settings} settings in {groups} setting groups "
                    "updated.".format(groups=len(count),
                                      settings=sum(
                                          len(settings)
                                          for settings in count.values())),
                    fg="green")
コード例 #2
0
ファイル: main.py プロジェクト: eirnym/flaskbb
def upgrade(all_latest, fixture, force):
    """Updates the migrations and fixtures."""
    if all_latest:
        click.secho("[+] Upgrading migrations to the latest version...",
                    fg="cyan")
        alembic.upgrade()

    if fixture or all_latest:
        try:
            settings = import_string(
                "flaskbb.fixtures.{}".format(fixture)
            )
            settings = settings.fixture
        except ImportError:
            raise FlaskBBCLIError("{} fixture is not available"
                                  .format(fixture), fg="red")

        click.secho("[+] Updating fixtures...", fg="cyan")
        count = update_settings_from_fixture(
            fixture=settings, overwrite_group=force, overwrite_setting=force
        )
        click.secho("[+] {settings} settings in {groups} setting groups "
                    "updated.".format(groups=len(count), settings=sum(
                        len(settings) for settings in count.values())
                    ), fg="green")
コード例 #3
0
ファイル: main.py プロジェクト: xinuguru/lawboard
def populate(bulk_data, test_data, posts, topics, force, initdb):
    """Creates the necessary tables and groups for FlaskBB."""
    if force:
        click.secho("[+] Recreating database...", fg="cyan")
        drop_database(db.engine.url)

        # do not initialize the db if -i is passed
        if not initdb:
            alembic.upgrade()

    if initdb:
        click.secho("[+] Initializing database...", fg="cyan")
        alembic.upgrade()

    if test_data:
        click.secho("[+] Adding some test data...", fg="cyan")
        create_test_data()

    if bulk_data:
        timer = time.time()
        topic_count, post_count = insert_bulk_data(int(topics), int(posts))
        elapsed = time.time() - timer
        click.secho(
            "[+] It took {} seconds to create {} topics and {} posts".format(
                elapsed, topic_count, post_count),
            fg="cyan")

    # this just makes the most sense for the command name; use -i to
    # init the db as well
    if not test_data:
        click.secho("[+] Populating the database with some defaults...",
                    fg="cyan")
        create_default_groups()
        create_default_settings()
コード例 #4
0
ファイル: main.py プロジェクト: xinuguru/lawboard
def install(welcome, force, username, email, password, group):
    """Installs flaskbb. If no arguments are used, an interactive setup
    will be run.
    """
    click.secho("[+] Installing FlaskBB...", fg="cyan")
    if database_exists(db.engine.url):
        if force or click.confirm(
                click.style(
                    "Existing database found. Do you want to delete the old one and "
                    "create a new one?",
                    fg="magenta")):
            drop_database(db.engine.url)
        else:
            sys.exit(0)
    create_database(db.engine.url)
    alembic.upgrade()

    click.secho("[+] Creating default settings...", fg="cyan")
    create_default_groups()
    create_default_settings()

    click.secho("[+] Creating admin user...", fg="cyan")
    prompt_save_user(username, email, password, group)

    if welcome:
        click.secho("[+] Creating welcome forum...", fg="cyan")
        create_welcome_forum()

    click.secho("[+] Compiling translations...", fg="cyan")
    compile_translations()

    click.secho("[+] FlaskBB has been successfully installed!",
                fg="green",
                bold=True)
コード例 #5
0
ファイル: main.py プロジェクト: xiaoyu0/flaskbb
def populate(bulk_data, test_data, posts, topics, force, initdb):
    """Creates the necessary tables and groups for FlaskBB."""
    if force:
        click.secho("[+] Recreating database...", fg="cyan")
        drop_database(db.engine.url)

        # do not initialize the db if -i is passed
        if not initdb:
            alembic.upgrade()

    if initdb:
        click.secho("[+] Initializing database...", fg="cyan")
        alembic.upgrade()

    if test_data:
        click.secho("[+] Adding some test data...", fg="cyan")
        create_test_data()

    if bulk_data:
        timer = time.time()
        topic_count, post_count = insert_bulk_data(int(topics), int(posts))
        elapsed = time.time() - timer
        click.secho("[+] It took {} seconds to create {} topics and {} posts"
                    .format(elapsed, topic_count, post_count), fg="cyan")

    # this just makes the most sense for the command name; use -i to
    # init the db as well
    if not test_data:
        click.secho("[+] Populating the database with some defaults...",
                    fg="cyan")
        create_default_groups()
        create_default_settings()
コード例 #6
0
ファイル: main.py プロジェクト: xiaoyu0/flaskbb
def install(welcome, force, username, email, password, group):
    """Installs flaskbb. If no arguments are used, an interactive setup
    will be run.
    """
    click.secho("[+] Installing FlaskBB...", fg="cyan")
    if database_exists(db.engine.url):
        if force or click.confirm(click.style(
            "Existing database found. Do you want to delete the old one and "
            "create a new one?", fg="magenta")
        ):
            drop_database(db.engine.url)
        else:
            sys.exit(0)
    create_database(db.engine.url)
    alembic.upgrade()

    click.secho("[+] Creating default settings...", fg="cyan")
    create_default_groups()
    create_default_settings()

    click.secho("[+] Creating admin user...", fg="cyan")
    prompt_save_user(username, email, password, group)

    if welcome:
        click.secho("[+] Creating welcome forum...", fg="cyan")
        create_welcome_forum()

    click.secho("[+] Compiling translations...", fg="cyan")
    compile_translations()

    click.secho("[+] FlaskBB has been successfully installed!",
                fg="green", bold=True)
コード例 #7
0
ファイル: test_populate.py プロジェクト: eirnym/flaskbb
def test_migrations_upgrade():
    with pytest.raises(OperationalError):
        User.query.all()

    # ensure that the database is created
    create_database(db.engine.url)

    alembic.upgrade()
    assert len(User.query.all()) == 0

    drop_database(db.engine.url)
コード例 #8
0
def test_migrations_upgrade():
    with pytest.raises(OperationalError):
        User.query.all()

    # ensure that the database is created
    create_database(db.engine.url)

    alembic.upgrade()
    assert len(User.query.all()) == 0

    drop_database(db.engine.url)
コード例 #9
0
def run_plugin_migrations(plugins=None):
    """Runs the migrations for a list of plugins.

    :param plugins: A iterable of plugins to run the migrations for. If set
                    to ``None``, all external plugin migrations will be run.
    """
    if plugins is None:
        plugins = current_app.pluggy.get_external_plugins()

    for plugin in plugins:
        plugin_name = current_app.pluggy.get_name(plugin)
        if not os.path.exists(os.path.join(plugin.__path__[0], "migrations")):
            logger.debug("No migrations found for plugin %s" % plugin_name)
            continue
        try:
            alembic.upgrade(target="{}@head".format(plugin_name))
        except CommandError as exc:
            logger.debug("Couldn't run migrations for plugin {} because of "
                         "following exception: ".format(plugin_name),
                         exc_info=exc)
コード例 #10
0
ファイル: populate.py プロジェクト: eirnym/flaskbb
def run_plugin_migrations(plugins=None):
    """Runs the migrations for a list of plugins.

    :param plugins: A iterable of plugins to run the migrations for. If set
                    to ``None``, all external plugin migrations will be run.
    """
    if plugins is None:
        plugins = current_app.pluggy.get_external_plugins()

    for plugin in plugins:
        plugin_name = current_app.pluggy.get_name(plugin)
        if not os.path.exists(os.path.join(plugin.__path__[0], "migrations")):
            logger.debug("No migrations found for plugin %s" % plugin_name)
            continue
        try:
            alembic.upgrade(target="{}@head".format(plugin_name))
        except CommandError as exc:
            logger.debug("Couldn't run migrations for plugin {} because of "
                         "following exception: ".format(plugin_name),
                         exc_info=exc)