Example #1
0
def drop(drop_all=False):
    """ Drop tables in project database
    """

    engine = current_app.extensions['meowth_dbutils'].db.engine
    if current_app.extensions['meowth_dbutils'].metadata.bind is None:
        current_app.extensions['meowth_dbutils'].metadata.bind = engine
    with perform(
            name='dbutils drop',
            before='Dropping all project tables',
            fail='Error occured while droping project tables',
    ):
        current_app.extensions['meowth_dbutils'].metadata.drop_all()
    with perform(
            name='dbutils drop',
            before='Dropping alembic versioning table',
            fail='Error occured while dropping alembic table',
    ):
        engine.execute('drop table if exists alembic_version')
    if drop_all:
        with perform(
                name='dbutils drop',
                before='Dropping all other tables in database',
                fail='Error occured while dropping other tables',
        ):
            current_app.extensions['meowth_dbutils'].db.reflect()
            current_app.extensions['meowth_dbutils'].db.drop_all()
Example #2
0
def drop(drop_all=False):
    """ Drop tables in project database
    """

    engine = current_app.extensions['meowth_dbutils'].db.engine
    if current_app.extensions['meowth_dbutils'].metadata.bind is None:
        current_app.extensions['meowth_dbutils'].metadata.bind = engine
    with perform(
        name='dbutils drop',
        before='Dropping all project tables',
        fail='Error occured while droping project tables',
    ):
        current_app.extensions['meowth_dbutils'].metadata.drop_all()
    with perform(
        name='dbutils drop',
        before='Dropping alembic versioning table',
        fail='Error occured while dropping alembic table',
    ):
        engine.execute('drop table if exists alembic_version')
    if drop_all:
        with perform(
            name='dbutils drop',
            before='Dropping all other tables in database',
            fail='Error occured while dropping other tables',
        ):
            current_app.extensions['meowth_dbutils'].db.reflect()
            current_app.extensions['meowth_dbutils'].db.drop_all()
Example #3
0
def npm():
    """ Run npm install script """
    with perform(
            name='static npm',
            before='run npm install',
    ):
        alt_exec(cmd=["npm", "install"], )
Example #4
0
def load_images(subdir):
    """ Load dummy images to populate gallery
    """
    with perform(name='dbutils load_images',
                 before='Loading images to gallery',
                 fail='Error occured while loading images to gallery',
                 after='Images succesfully loaded'):
        load_dummy_images(subdir)
Example #5
0
def npm():
    """ Run npm install script """
    with perform(
            name='static npm',
            before='run npm install',
    ):
        alt_exec(
            cmd=["npm", "install"],
        )
Example #6
0
def load_images(count=100):
    """ Load dummy images to populate gallery
    """

    with perform(
        name='dbutils load_images',
        before='Loading %d dummy images to gallery' % count,
        fail='Error occured while loading images to gallery',
    ):
        load_dummy_images(count)
Example #7
0
def load_images(subdir):
    """ Load dummy images to populate gallery
    """
    with perform(
        name='dbutils load_images',
        before='Loading images to gallery',
        fail='Error occured while loading images to gallery',
        after='Images succesfully loaded'
    ):
        load_dummy_images(subdir)
Example #8
0
def load_images(count=100):
    """ Load dummy images to populate gallery
    """

    with perform(
            name='dbutils load_images',
            before='Loading %d dummy images to gallery' % count,
            fail='Error occured while loading images to gallery',
    ):
        load_dummy_images(count)
Example #9
0
def clean():
    """ Clean built static files """
    with perform(
            name='static clean',
            before='run gulp clean',
    ):
        alt_exec(
            cmd=["gulp", "clean"],
            alt=["./node_modules/gulp/bin/gulp.js", "clean"],
        )
Example #10
0
def bower():
    """ Run bower install script """
    with perform(
            name='static bower',
            before='run bower install',
    ):
        alt_exec(
            cmd=["bower", "install"],
            alt=["./node_modules/bower/bin/bower", "install"],
        )
Example #11
0
def clean():
    """ Clean built static files """
    with perform(
            name='static clean',
            before='run gulp clean',
    ):
        alt_exec(
            cmd=["gulp", "clean"],
            alt=["./node_modules/gulp/bin/gulp.js", "clean"],
        )
Example #12
0
def bower():
    """ Run bower install script """
    with perform(
            name='static bower',
            before='run bower install',
    ):
        alt_exec(
            cmd=["bower", "install"],
            alt=["./node_modules/bower/bin/bower", "install"],
        )
Example #13
0
def populate(directory=None):
    """ Populate database with fixtures
    """

    if directory is None:
        directory = current_app.config['FIXTURES_DIR']
    with perform(
            name='dbutils populate',
            before='Loading fixtures from directory %s' % directory,
            fail='Error occured while loading fixtures',
    ):
        load_fixtures(directory)
Example #14
0
def populate(directory=None):
    """ Populate database with fixtures
    """

    if directory is None:
        directory = current_app.config['FIXTURES_DIR']
    with perform(
        name='dbutils populate',
        before='Loading fixtures from directory %s' % directory,
        fail='Error occured while loading fixtures',
    ):
        load_fixtures(directory)
Example #15
0
def gulp(deploy_type=None):
    """ Run gulp build script """
    with perform(
            name='static gulp',
            before='run gulp',
    ):
        cmd_args = list()
        if deploy_type is not None:
            cmd_args.append("--type")
            cmd_args.append(deploy_type)

        alt_exec(
            cmd=["gulp"] + cmd_args,
            alt=["./node_modules/gulp/bin/gulp.js"] + cmd_args,
        )
Example #16
0
def gulp(deploy_type=None):
    """ Run gulp build script """
    with perform(
            name='static gulp',
            before='run gulp',
    ):
        cmd_args = list()
        if deploy_type is not None:
            cmd_args.append("--type")
            cmd_args.append(deploy_type)

        alt_exec(
            cmd=["gulp"] + cmd_args,
            alt=["./node_modules/gulp/bin/gulp.js"] + cmd_args,
        )
Example #17
0
def bower(allow_root, silent):
    """ Run bower install script """
    with perform(
            name='static bower',
            before='run bower install',
    ):
        cmd_args = list()
        if allow_root:
            cmd_args.append("--allow-root")

        if silent:
            cmd_args.append("--silent")

        alt_exec(
            cmd=["bower", "install"] + cmd_args,
            alt=["./node_modules/bower/bin/bower", "install"] + cmd_args,
        )
Example #18
0
def bower(allow_root, silent):
    """ Run bower install script """
    with perform(
            name='static bower',
            before='run bower install',
    ):
        cmd_args = list()
        if allow_root:
            cmd_args.append("--allow-root")

        if silent:
            cmd_args.append("--silent")

        alt_exec(
            cmd=["bower", "install"] + cmd_args,
            alt=["./node_modules/bower/bin/bower", "install"] + cmd_args,
        )
Example #19
0
def createsuperuser(login=None, email=None, password=None):
    """ Create user with admin rights"""
    login = login or ask_input('Введите логин')
    email = email or ask_input('Введите адрес электронной почты')
    passwd = password or ask_input('Введите пароль', hidden=True)
    confirmation = password or ask_input('Подтвердите пароль', hidden=True)

    while passwd != confirmation:
        print('Пароли не совпадают! Похоже, вы опечатались.')
        while True:
            choice = input('Повторить ввод? (y/n) ').lower()
            if choice in 'yes':
                passwd = ask_input('Введите пароль', hidden=True)
                confirmation = ask_input('Подтвердите пароль', hidden=True)
                break
            elif choice in 'no':
                return
            else:
                print('Пожалуйста, ответьте y (yes) или n (no)')

    with disable_csrf(app):
        form = HelperForm(
            name='dummy',
            surname='dummy',
            password=passwd,
            confirmation=passwd,
        )
        # dodge filling obj_data , just like browser form filling
        # (Existence validation comes false positive)
        form.login.data = login
        form.email.data = email
        if not form.validate():
            errors = [err for field in form.errors.values() for err in field]
            for error in errors:
                print(error)
            return
        else:
            with app.app_context(), perform(
                name='createsuperuser',
                before='Creating user',
                fail='Error occured while creating user',
                after='Superuser has been succesfully created!',
            ):
                User.bl.create_superuser(login, passwd, email)
Example #20
0
def createsuperuser(login=None, email=None, password=None):
    """ Create user with admin rights"""
    login = login or ask_input('Введите логин')
    email = email or ask_input('Введите адрес электронной почты')
    passwd = password or ask_input('Введите пароль', hidden=True)
    confirmation = password or ask_input('Подтвердите пароль', hidden=True)

    while passwd != confirmation:
        print('Пароли не совпадают! Похоже, вы опечатались.')
        while True:
            choice = input('Повторить ввод? (y/n) ').lower()
            if choice in 'yes':
                passwd = ask_input('Введите пароль', hidden=True)
                confirmation = ask_input('Подтвердите пароль', hidden=True)
                break
            elif choice in 'no':
                return
            else:
                print('Пожалуйста, ответьте y (yes) или n (no)')

    with disable_csrf(app):
        form = HelperForm(
            name='dummy',
            surname='dummy',
            password=passwd,
            confirmation=passwd,
        )
        # dodge filling obj_data , just like browser form filling
        # (Existence validation comes false positive)
        form.login.data = login
        form.email.data = email
        if not form.validate():
            errors = [err for field in form.errors.values() for err in field]
            for error in errors:
                print(error)
            return
        else:
            with app.app_context(), perform(
                    name='createsuperuser',
                    before='Creating user',
                    fail='Error occured while creating user',
                    after='Superuser has been succesfully created!',
            ):
                User.bl.create_superuser(login, passwd, email)
Example #21
0
def init(
    populate_after_init=False,
    directory=None,
    drop_all=False,
    load_gallery_images=False,
    image_count=100,
):
    """ Create a new clean database
    """

    drop(drop_all=drop_all)
    with perform(
            name='dbutils init',
            before='initializing database to its latest version',
    ):
        migrate_upgrade()
    if populate_after_init:
        populate(directory)
    if load_gallery_images:
        load_images(image_count)
Example #22
0
def init(
    populate_after_init=False,
    directory=None,
    drop_all=False,
    load_gallery_images=False,
    image_count=100,
):
    """ Create a new clean database
    """

    drop(drop_all=drop_all)
    with perform(
        name='dbutils init',
        before='initializing database to its latest version',
    ):
        migrate_upgrade()
    if populate_after_init:
        populate(directory)
    if load_gallery_images:
        load_images(image_count)