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)
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)
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 cli(ctx, plugin=None, all_plugins=False): if plugin and all_plugins: raise click.BadParameter('cannot combine --plugin and --all-plugins') if all_plugins and ctx.invoked_subcommand in ('migrate', 'revision', 'downgrade', 'stamp', 'edit'): raise click.UsageError('this command requires an explicit plugin') if (all_plugins or plugin) and ctx.invoked_subcommand == 'prepare': raise click.UsageError('this command is not available for plugins (use `upgrade` instead)') if plugin and not plugin_engine.get_plugin(plugin): raise click.BadParameter('plugin does not exist or is not loaded', param_hint='plugin') migrate.init_app(current_app, db, os.path.join(current_app.root_path, 'migrations'))
def setup(main_zodb_uri, rb_zodb_uri, sqlalchemy_uri): app = Flask('migration') fix_root_path(app) app.config['SQLALCHEMY_DATABASE_URI'] = sqlalchemy_uri db.init_app(app) alembic_migrate.init_app(app, db, os.path.join(app.root_path, '..', 'migrations')) main_root = UnbreakingDB(get_storage(main_zodb_uri)).open().root() rb_root = UnbreakingDB(get_storage(rb_zodb_uri)).open().root() return main_root, rb_root, app
def setup(self): 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) setup_request_stats(app) if self.dblog: app.debug = True apply_db_loggers(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(): request_stats_request_started() if not self.pre_check(): sys.exit(1) 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)
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)
def main(): app = make_app(set_path=True) migrate.init_app(app, db, os.path.join(app.root_path, '..', 'migrations')) manager = Manager(app, with_default_commands=False) manager.add_command('shell', IndicoShell()) manager.add_command('admin', IndicoAdminManager) manager.add_command('db', DatabaseManager) manager.add_command('plugindb', PluginDatabaseManager) manager.add_command('runserver', IndicoDevServer()) manager.add_command('i18n', IndicoI18nManager) signals.plugin.cli.send(manager) try: manager.run() except KeyboardInterrupt: print sys.exit(1)
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
def main(): app = make_app(set_path=True) migrate.init_app(app, db, os.path.join(app.root_path, "..", "migrations")) manager = Manager(app, with_default_commands=False) manager.add_command("shell", IndicoShell()) manager.add_command("admin", IndicoAdminManager) manager.add_command("db", DatabaseManager) manager.add_command("plugindb", PluginDatabaseManager) manager.add_command("runserver", IndicoDevServer()) manager.add_command("i18n", IndicoI18nManager) manager.add_command("celery", IndicoCeleryCommand) signals.plugin.cli.send(manager) try: manager.run() except KeyboardInterrupt: print sys.exit(1)
def app_factory(): app = make_app() migrate.init_app(app, db, os.path.join(app.root_path, '..', 'migrations')) return app