Exemplo n.º 1
0
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")
        db.drop_all()

        # do not initialize the db if -i is passed
        if not initdb:
            create_latest_db()

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

    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()
Exemplo n.º 2
0
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)
    upgrade_database()

    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)
Exemplo n.º 3
0
def install(welcome, force, username, email, password):
    """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")):
            db.drop_all()
        else:
            sys.exit(0)

    # creating database from scratch and 'stamping it'
    create_latest_db()

    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, "admin")

    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)
Exemplo n.º 4
0
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:
            upgrade_database()

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

    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()
Exemplo n.º 5
0
def create_default_data():
    """
    This should be created by every flaskbb installation
    """
    db.create_all()
    create_default_groups()
    create_welcome_forum()
Exemplo n.º 6
0
def initdb(default_settings=True):
    """Creates the database."""
    upgrade()

    if default_settings:
        print("Creating default data...")
        create_default_groups()
        create_default_settings()
Exemplo n.º 7
0
def initdb(default_settings=True):
    """Creates the database."""
    upgrade()

    if default_settings:
        print("Creating default data...")
        create_default_groups()
        create_default_settings()
Exemplo n.º 8
0
def test_create_default_groups(database):
    """Test that the default groups are created correctly."""

    assert Group.query.count() == 0

    create_default_groups()

    assert Group.query.count() == len(group_fixture)

    for key, attributes in group_fixture.items():
        group = Group.query.filter_by(name=key).first()

        for attribute, value in attributes.items():
            assert getattr(group, attribute) == value
Exemplo n.º 9
0
def test_create_default_groups(database):
    """Test that the default groups are created correctly."""

    assert Group.query.count() == 0

    create_default_groups()

    assert Group.query.count() == len(group_fixture)

    for key, attributes in group_fixture.items():
        group = Group.query.filter_by(name=key).first()

        for attribute, value in attributes.items():
            assert getattr(group, attribute) == value
Exemplo n.º 10
0
def install(welcome, force, username, email, password, no_plugins):
    """Installs flaskbb. If no arguments are used, an interactive setup
    will be run.
    """
    if not current_app.config["CONFIG_PATH"]:
        click.secho(
            "[!] No 'flaskbb.cfg' config found. "
            "You can generate a configuration file with 'flaskbb makeconfig'.",
            fg="red",
        )
        sys.exit(1)

    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",
                )):
            db.drop_all()
        else:
            sys.exit(0)

    # creating database from scratch and 'stamping it'
    create_latest_db()

    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, "admin")

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

    if not no_plugins:
        click.secho("[+] Installing default plugins...", fg="cyan")
        run_plugin_migrations()

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

    click.secho("[+] FlaskBB has been successfully installed!",
                fg="green",
                bold=True)
Exemplo n.º 11
0
def initflaskbb(username=None, password=None, email=None):
    """Initializes FlaskBB with all necessary data"""

    app.logger.info("Creating default groups...")
    try:
        create_default_groups()
    except IntegrityError:
        app.logger.error("Couldn't create the default groups because they are\
                          already exist!")
        if prompt_bool("Do you want to recreate the database? (y/n)"):
            db.session.rollback()
            db.drop_all()
            db.create_all()
            create_default_groups()
        else:
            sys.exit(0)
    except OperationalError:
        app.logger.error("No database found.")
        if prompt_bool("Do you want to create the database? (y/n)"):
            db.session.rollback()
            db.create_all()
            create_default_groups()
        else:
            sys.exit(0)

    app.logger.info("Creating admin user...")
    if username and password and email:
        create_admin_user(username=username, password=password, email=email)
    else:
        create_admin()

    app.logger.info("Creating welcome forum...")
    create_welcome_forum()

    app.logger.info("Congratulations! FlaskBB has been successfully installed")
Exemplo n.º 12
0
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")
        db.drop_all()

        # do not initialize the db if -i is passed
        if not initdb:
            create_latest_db()

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

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

    if bulk_data:
        click.secho("[+] Adding a lot of test data...", fg="cyan")
        timer = time.time()
        rv = insert_bulk_data(int(topics), int(posts))
        if not rv and not test_data:
            create_test_data()
            rv = insert_bulk_data(int(topics), int(posts))
        elapsed = time.time() - timer
        click.secho("[+] It took {:.2f} seconds to create {} topics and {} "
                    "posts.".format(elapsed, rv[0], rv[1]), fg="cyan")

    # this just makes the most sense for the command name; use -i to
    # init the db as well
    if not test_data and not bulk_data:
        click.secho("[+] Populating the database with some defaults...",
                    fg="cyan")
        create_default_groups()
        create_default_settings()
Exemplo n.º 13
0
def install(username=None, password=None, email=None):
    """Installs FlaskBB with all necessary data."""

    print("Creating default data...")
    try:
        create_default_groups()
        create_default_settings()
    except IntegrityError:
        print("Couldn't create the default data because it already exist!")
        if prompt_bool("Found an existing database."
                       "Do you want to recreate the database? (y/n)"):
            db.session.rollback()
            db.drop_all()
            upgrade()
            create_default_groups()
            create_default_settings()
        else:
            sys.exit(0)
    except OperationalError:
        print("No database found.")
        if prompt_bool("Do you want to create the database now? (y/n)"):
            db.session.rollback()
            upgrade()
            create_default_groups()
            create_default_settings()
        else:
            sys.exit(0)

    print("Creating admin user...")
    if username and password and email:
        create_admin_user(username=username, password=password, email=email)
    else:
        create_admin()

    print("Creating welcome forum...")
    create_welcome_forum()

    print("Compiling translations...")
    compile_translations()

    if prompt_bool("Do you want to use Emojis? (y/n)"):
        print("Downloading emojis. This can take a few minutes.")
        download_emoji()

    print("Congratulations! FlaskBB has been successfully installed")
Exemplo n.º 14
0
def install(username=None, password=None, email=None):
    """Installs FlaskBB with all necessary data."""

    print("Creating default data...")
    try:
        create_default_groups()
        create_default_settings()
    except IntegrityError:
        print("Couldn't create the default data because it already exist!")
        if prompt_bool("Found an existing database."
                       "Do you want to recreate the database? (y/n)"):
            db.session.rollback()
            db.drop_all()
            upgrade()
            create_default_groups()
            create_default_settings()
        else:
            sys.exit(0)
    except OperationalError:
        print("No database found.")
        if prompt_bool("Do you want to create the database now? (y/n)"):
            db.session.rollback()
            upgrade()
            create_default_groups()
            create_default_settings()
        else:
            sys.exit(0)

    print("Creating admin user...")
    if username and password and email:
        create_admin_user(username=username, password=password, email=email)
    else:
        create_admin()

    print("Creating welcome forum...")
    create_welcome_forum()

    print("Compiling translations...")
    compile_translations()

    if prompt_bool("Do you want to use Emojis? (y/n)"):
        print("Downloading emojis. This can take a few minutes.")
        download_emoji()

    print("Congratulations! FlaskBB has been successfully installed")
Exemplo n.º 15
0
def default_groups(database):
    """Creates the default groups"""
    return create_default_groups()
Exemplo n.º 16
0
Arquivo: app.py Projeto: 0xsKu/flaskbb
def default_groups(database):
    """Creates the default groups"""
    return create_default_groups()