Ejemplo n.º 1
0
def default_data(base_app):
    from appenlight.models.services.config import ConfigService
    from appenlight.lib import get_callable
    transaction.begin()
    ConfigService.setup_default_values()
    for plugin_name, config in base_app.registry.appenlight_plugins.items():
        if config['default_values_setter']:
            get_callable(config['default_values_setter'])()
    transaction.commit()
Ejemplo n.º 2
0
def main(argv=sys.argv):
    parser = argparse.ArgumentParser(
        description="Migrate AppEnlight database to latest version",
        add_help=False)
    parser.add_argument("-c",
                        "--config",
                        required=True,
                        help="Configuration ini file of application")
    args = parser.parse_args()
    config_uri = args.config

    setup_logging(config_uri)
    bootstrap(config_uri)
    registry = get_current_registry()
    alembic_cfg = Config()
    alembic_cfg.set_main_option("sqlalchemy.echo", "true")
    alembic_cfg.set_main_option("script_location",
                                "ziggurat_foundations:migrations")
    alembic_cfg.set_main_option("sqlalchemy.url",
                                registry.settings["sqlalchemy.url"])
    command.upgrade(alembic_cfg, "head")
    alembic_cfg = Config()
    alembic_cfg.set_main_option("sqlalchemy.echo", "true")
    alembic_cfg.set_main_option("script_location", "appenlight:migrations")
    alembic_cfg.set_main_option("sqlalchemy.url",
                                registry.settings["sqlalchemy.url"])
    command.upgrade(alembic_cfg, "head")

    for plugin_name, config in registry.appenlight_plugins.items():
        if config["sqlalchemy_migrations"]:
            alembic_cfg = Config()
            alembic_cfg.set_main_option("script_location",
                                        config["sqlalchemy_migrations"])
            alembic_cfg.set_main_option("sqlalchemy.url",
                                        registry.settings["sqlalchemy.url"])
            alembic_cfg.set_main_option("sqlalchemy.echo", "true")
            command.upgrade(alembic_cfg, "head")

    with get_current_request().tm:
        ConfigService.setup_default_values()

        for plugin_name, config in registry.appenlight_plugins.items():
            if config["default_values_setter"]:
                get_callable(config["default_values_setter"])()
Ejemplo n.º 3
0
def main():
    """
    Recreates Elasticsearch indexes
    Performs reindex of whole db to Elasticsearch

    """

    # need parser twice because we first need to load ini file
    # bootstrap pyramid and then load plugins
    pre_parser = argparse.ArgumentParser(description='Reindex AppEnlight data',
                                         add_help=False)
    pre_parser.add_argument('-c',
                            '--config',
                            required=True,
                            help='Configuration ini file of application')
    pre_parser.add_argument('-h', '--help', help='Show help', nargs='?')
    pre_parser.add_argument(
        '-t',
        '--types',
        nargs='+',
        help='Which parts of database should get reindexed')
    args = pre_parser.parse_args()

    config_uri = args.config
    setup_logging(config_uri)
    log.setLevel(logging.INFO)
    env = bootstrap(config_uri)
    parser = argparse.ArgumentParser(description='Reindex AppEnlight data')
    choices = {
        'reports': 'appenlight.scripts.reindex_elasticsearch:reindex_reports',
        'logs': 'appenlight.scripts.reindex_elasticsearch:reindex_logs',
        'metrics': 'appenlight.scripts.reindex_elasticsearch:reindex_metrics',
        'slow_calls':
        'appenlight.scripts.reindex_elasticsearch:reindex_slow_calls',
        'template': 'appenlight.scripts.reindex_elasticsearch:update_template'
    }
    for k, v in env['registry'].appenlight_plugins.items():
        if v.get('fulltext_indexer'):
            choices[k] = v['fulltext_indexer']
    parser.add_argument('-t',
                        '--types',
                        nargs='*',
                        choices=['all'] + list(choices.keys()),
                        default=['all'],
                        help='Which parts of database should get reindexed')
    parser.add_argument('-c',
                        '--config',
                        required=True,
                        help='Configuration ini file of application')
    args = parser.parse_args()

    if 'all' in args.types:
        args.types = list(choices.keys())

    log.info('settings {}'.format(args.types))

    if 'template' in args.types:
        get_callable(choices['template'])()
        args.types.remove('template')
    for selected in args.types:
        get_callable(choices[selected])()