Exemplo n.º 1
0
    def sync(cls):
        """Sync cache by latest data"""

        def sync_tables(tables):
            for table in tables:
                table.sync()
                click.echo(".", nl=False, err=True)

        cache_table_map = cls.get_cache_tables(sync_version=True)
        tables = list(cache_table_map.values())

        # Inserting version table at start
        tables.insert(0, Version)

        try:
            LOG.info("Updating cache", nl=False)
            sync_tables(tables)

        except (OperationalError, IntegrityError):
            click.echo(" [Fail]")
            # init db handle once (recreating db if some schema changes are there)
            LOG.info("Removing existing db and updating cache again")
            init_db_handle()
            LOG.info("Updating cache", nl=False)
            sync_tables(tables)
        click.echo(" [Done]", err=True)
Exemplo n.º 2
0
    def clear_entities(cls):
        """Clear data present in the cache tables"""

        # For now clearing means erasing all data. So reinitialising whole database
        init_db_handle()
Exemplo n.º 3
0
def init_db():
    LOG.info("Creating local database")
    init_db_handle()