def init(): global _LocalStorage if _LocalStorage is not None: lg.warn('local storage already initialized') return contract_chain_dir = os.path.join(settings.ContractChainDir(), 'current') _LocalStorage = Database(contract_chain_dir) _LocalStorage.custom_header = coins_index.make_custom_header() if _Debug: lg.out(_DebugLevel, 'coins_db.init in %s' % contract_chain_dir) if db().exists(): try: db().open() except: temp_dir = os.path.join(settings.ContractChainDir(), 'tmp') if os.path.isdir(temp_dir): bpio._dir_remove(temp_dir) tmpdb = regenerate_indexes(temp_dir) rewrite_indexes(db(), tmpdb) bpio._dir_remove(temp_dir) db().open() db().reindex() else: db().create() refresh_indexes(db())
def regenerate_indexes(temp_dir): """ """ tmpdb = Database(temp_dir) tmpdb.custom_header = coins_index.make_custom_header() tmpdb.create() refresh_indexes(tmpdb) tmpdb.close() return tmpdb