コード例 #1
0
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))
コード例 #2
0
ファイル: cli.py プロジェクト: marcosmolla/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
        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)
コード例 #3
0
ファイル: cli.py プロジェクト: 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)
コード例 #4
0
ファイル: cli.py プロジェクト: jacquesd/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
        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)