def main(main_uri, rb_uri, sqla_uri, photo_path, drop, merged_avatars):
    update_session_options(db)  # get rid of the zope transaction extension
    main_root, rb_root, app = setup(main_uri, rb_uri, sqla_uri)
    global tz
    try:
        tz = pytz.timezone(main_root['MaKaCInfo']['main'].getTimezone())
    except KeyError:
        tz = pytz.utc

    start = time.clock()
    with app.app_context():
        if drop:
            print cformat('%{yellow!}*** DANGER')
            print cformat('%{yellow!}***%{reset} '
                          '%{red!}ALL DATA%{reset} in your database %{yellow!}{!r}%{reset} will be '
                          '%{red!}PERMANENTLY ERASED%{reset}!').format(db.engine.url)
            if raw_input(cformat('%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: ')) != 'YES':
                print 'Aborting'
                sys.exit(1)
            delete_all_tables(db)
        stamp()
        db.create_all()
        if Location.find().count():
            # Usually there's no good reason to migrate with data in the DB. However, during development one might
            # comment out some migration tasks and run the migration anyway.
            print cformat('%{yellow!}*** WARNING')
            print cformat('%{yellow!}***%{reset} Your database is not empty, migration will most likely fail!')
            if raw_input(cformat('%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: ')) != 'YES':
                print 'Aborting'
                sys.exit(1)
        migrate(main_root, rb_root, photo_path, merged_avatars)
    print 'migration took {} seconds'.format((time.clock() - start))
Example #2
0
    def setup(self):
        update_session_options(db)  # get rid of the zope transaction extension

        self.app = app = IndicoFlask('indico_zodbimport')
        app.config['PLUGINENGINE_NAMESPACE'] = 'indico.plugins'
        app.config['PLUGINENGINE_PLUGINS'] = self.plugins
        app.config['SQLALCHEMY_DATABASE_URI'] = self.sqlalchemy_uri
        plugin_engine.init_app(app)
        if not plugin_engine.load_plugins(app):
            print cformat(
                '%{red!}Could not load some plugins: {}%{reset}').format(
                    ', '.join(plugin_engine.get_failed_plugins(app)))
            sys.exit(1)
        db.init_app(app)
        import_all_models()
        alembic_migrate.init_app(
            app, db, os.path.join(app.root_path, '..', 'migrations'))

        self.connect_zodb()

        try:
            self.tz = pytz.timezone(
                getattr(self.zodb_root['MaKaCInfo']['main'], '_timezone',
                        'UTC'))
        except KeyError:
            self.tz = pytz.utc

        with app.app_context():
            if not self.pre_check():
                sys.exit(1)

            if self.destructive:
                print cformat('%{yellow!}*** DANGER')
                print cformat(
                    '%{yellow!}***%{reset} '
                    '%{red!}ALL DATA%{reset} in your database %{yellow!}{!r}%{reset} will be '
                    '%{red!}PERMANENTLY ERASED%{reset}!').format(db.engine.url)
                if raw_input(
                        cformat(
                            '%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: '
                        )) != 'YES':
                    print 'Aborting'
                    sys.exit(1)
                delete_all_tables(db)
                stamp()
                db.create_all()
            if self.has_data():
                # Usually there's no good reason to migrate with data in the DB. However, during development one might
                # comment out some migration tasks and run the migration anyway.
                print cformat('%{yellow!}*** WARNING')
                print cformat(
                    '%{yellow!}***%{reset} Your database is not empty, migration will most likely fail!'
                )
                if raw_input(
                        cformat(
                            '%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: '
                        )) != 'YES':
                    print 'Aborting'
                    sys.exit(1)
Example #3
0
File: cli.py Project: florv/indico
    def setup(self):
        update_session_options(db)  # get rid of the zope transaction extension

        self.app = app = IndicoFlask("indico_zodbimport")
        app.config["PLUGINENGINE_NAMESPACE"] = "indico.plugins"
        app.config["PLUGINENGINE_PLUGINS"] = self.plugins
        app.config["SQLALCHEMY_DATABASE_URI"] = self.sqlalchemy_uri
        app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
        plugin_engine.init_app(app)
        if not plugin_engine.load_plugins(app):
            print(
                cformat("%{red!}Could not load some plugins: {}%{reset}").format(
                    ", ".join(plugin_engine.get_failed_plugins(app))
                )
            )
            sys.exit(1)
        db.init_app(app)
        import_all_models()
        alembic_migrate.init_app(app, db, os.path.join(app.root_path, "..", "migrations"))

        self.connect_zodb()

        try:
            self.tz = pytz.timezone(getattr(self.zodb_root["MaKaCInfo"]["main"], "_timezone", "UTC"))
        except KeyError:
            self.tz = pytz.utc

        with app.app_context():
            if not self.pre_check():
                sys.exit(1)

            if self.destructive:
                print(cformat("%{yellow!}*** DANGER"))
                print(
                    cformat(
                        "%{yellow!}***%{reset} "
                        "%{red!}ALL DATA%{reset} in your database %{yellow!}{!r}%{reset} will be "
                        "%{red!}PERMANENTLY ERASED%{reset}!"
                    ).format(db.engine.url)
                )
                if raw_input(cformat("%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: ")) != "YES":
                    print("Aborting")
                    sys.exit(1)
                delete_all_tables(db)
                stamp()
                db.create_all()
            if self.has_data():
                # Usually there's no good reason to migrate with data in the DB. However, during development one might
                # comment out some migration tasks and run the migration anyway.
                print(cformat("%{yellow!}*** WARNING"))
                print(
                    cformat(
                        "%{yellow!}***%{reset} Your database is not empty, migration may fail or add duplicate " "data!"
                    )
                )
                if raw_input(cformat("%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: ")) != "YES":
                    print("Aborting")
                    sys.exit(1)
Example #4
0
    def setup(self):
        update_session_options(db)  # get rid of the zope transaction extension

        self.app = app = IndicoFlask('indico_zodbimport')
        app.config['PLUGINENGINE_NAMESPACE'] = 'indico.plugins'
        app.config['PLUGINENGINE_PLUGINS'] = self.plugins
        app.config['SQLALCHEMY_DATABASE_URI'] = self.sqlalchemy_uri
        plugin_engine.init_app(app)
        if not plugin_engine.load_plugins(app):
            print(cformat('%{red!}Could not load some plugins: {}%{reset}').format(
                ', '.join(plugin_engine.get_failed_plugins(app))))
            sys.exit(1)
        db.init_app(app)
        import_all_models()
        alembic_migrate.init_app(app, db, os.path.join(app.root_path, '..', 'migrations'))

        self.connect_zodb()

        try:
            self.tz = pytz.timezone(getattr(self.zodb_root['MaKaCInfo']['main'], '_timezone', 'UTC'))
        except KeyError:
            self.tz = pytz.utc

        with app.app_context():
            if not self.pre_check():
                sys.exit(1)

            if self.destructive:
                print(cformat('%{yellow!}*** DANGER'))
                print(cformat('%{yellow!}***%{reset} '
                              '%{red!}ALL DATA%{reset} in your database %{yellow!}{!r}%{reset} will be '
                              '%{red!}PERMANENTLY ERASED%{reset}!').format(db.engine.url))
                if raw_input(cformat('%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: ')) != 'YES':
                    print('Aborting')
                    sys.exit(1)
                delete_all_tables(db)
                stamp()
                db.create_all()
            if self.has_data():
                # Usually there's no good reason to migrate with data in the DB. However, during development one might
                # comment out some migration tasks and run the migration anyway.
                print(cformat('%{yellow!}*** WARNING'))
                print(cformat('%{yellow!}***%{reset} Your database is not empty, migration may fail or add duplicate '
                              'data!'))
                if raw_input(cformat('%{yellow!}***%{reset} To confirm this, enter %{yellow!}YES%{reset}: ')) != 'YES':
                    print('Aborting')
                    sys.exit(1)
Example #5
0
def database(app, postgresql):
    """Creates a test database which is destroyed afterwards

    Used only internally, if you need to access the database use `db` instead to ensure
    your modifications are not persistent!
    """
    app.config['SQLALCHEMY_DATABASE_URI'] = postgresql
    configure_db(app)
    if 'INDICO_TEST_DATABASE_URI' in os.environ and os.environ.get('INDICO_TEST_DATABASE_HAS_TABLES') == '1':
        yield db_
        return
    with app.app_context():
        create_all_tables(db_)
    yield db_
    db_.session.remove()
    with app.app_context():
        delete_all_tables(db_)