def setup(logger, zodb_root, sqlalchemy_uri, dblog=False, restore=False): app = IndicoFlask('indico_migrate') app.config['PLUGINENGINE_NAMESPACE'] = 'indico.plugins' app.config['SQLALCHEMY_DATABASE_URI'] = sqlalchemy_uri app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True _monkeypatch_config() 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) if dblog: app.debug = True apply_db_loggers(app, force=True) db_logger = Logger.get('_db') db_logger.level = logging.DEBUG db_logger.propagate = False db_logger.addHandler(SocketHandler('127.0.0.1', 9020)) # avoid "no handlers registered" warnings logging.root.addHandler(logging.NullHandler()) import_all_models() configure_mappers() alembic_migrate.init_app(app, db, os.path.join(app.root_path, 'migrations')) try: tz = pytz.timezone( getattr(zodb_root['MaKaCInfo']['main'], '_timezone', 'UTC')) except KeyError: tz = pytz.utc with app.app_context(): if not restore: all_tables = sum(get_all_tables(db).values(), []) if all_tables: if db_has_data(): logger.fatal_error( 'Your database is not empty!\n' 'If you want to reset it, please drop and recreate it first.' ) else: # the DB is empty, prepare DB tables # prevent alembic from messing with the logging config tmp = logging.config.fileConfig logging.config.fileConfig = lambda fn: None prepare_db(empty=True, root_path=get_root_path('indico'), verbose=False) logging.config.fileConfig = tmp _create_oauth_apps() return app, tz
def setup(logger, zodb_root, sqlalchemy_uri, dblog=False, restore=False): app = IndicoFlask('indico_migrate') app.config['PLUGINENGINE_NAMESPACE'] = 'indico.plugins' app.config['SQLALCHEMY_DATABASE_URI'] = sqlalchemy_uri app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True _monkeypatch_config() 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) if dblog: app.debug = True apply_db_loggers(app) import_all_models() configure_mappers() alembic_migrate.init_app(app, db, os.path.join(app.root_path, 'migrations')) try: tz = pytz.timezone( getattr(zodb_root['MaKaCInfo']['main'], '_timezone', 'UTC')) except KeyError: tz = pytz.utc with app.app_context(): if not restore: all_tables = sum(get_all_tables(db).values(), []) if all_tables: if db_has_data(): logger.fatal_error( 'Your database is not empty!\n' 'If you want to reset it, please drop and recreate it first.' ) else: # the DB is empty, prepare DB tables prepare_db(empty=True, root_path=get_root_path('indico'), verbose=False) return app, tz