Beispiel #1
0
def refresh_indexes(db_instance):
    """
    """
    if _Debug:
        lg.out(_DebugLevel,
               'message_db.refresh_indexes in %s' % db_instance.path)
    ok = True
    for ind, ind_class in message_index.definitions():
        ind_obj = ind_class(db_instance.path, ind)
        if ind not in db_instance.indexes_names:
            try:
                db_instance.add_index(ind_obj, create=True)
                if _Debug:
                    lg.out(_DebugLevel, '        added index %s' % ind)
            except:
                if _Debug:
                    lg.out(_DebugLevel, '        index skipped %s' % ind)
        else:
            try:
                db_instance.edit_index(ind_obj, reindex=True)
            except:
                ok = False
                break
            if _Debug:
                lg.out(_DebugLevel, '        updated index %s' % ind)
    return ok
Beispiel #2
0
def refresh_indexes(db_instance, rewrite=True, reindex=True):
    """
    """
    if _Debug:
        lg.out(_DebugLevel, 'message_db.refresh_indexes in %s' % db_instance.path)
    ok = True
    for ind, ind_class_or_filename in message_index.definitions():
        if isinstance(ind_class_or_filename, str):
            chat_history_dir = db_instance.path
            target_index_filepath = os.path.join(chat_history_dir, '_indexes', ind_class_or_filename)
            if not os.path.exists(os.path.dirname(target_index_filepath)):
                bpio._dirs_make(os.path.dirname(target_index_filepath))
            bpio.WriteTextFile(
                target_index_filepath,
                bpio.ReadTextFile(os.path.join(bpio.getExecutableDir(), 'chat', 'indexes', ind_class_or_filename)),
            )
            ind_obj = 'path:%s' % os.path.basename(target_index_filepath)
        else:
            ind_obj = ind_class_or_filename(db_instance.path, ind)
        if ind not in db_instance.indexes_names:
            try:
                db_instance.add_index(ind_obj, create=True)
                if _Debug:
                    lg.out(_DebugLevel, '        added index %s' % ind)
            except:
                lg.exc('failed adding index "%r"' % ind)
        else:
            if rewrite:
                try:
                    db_instance.edit_index(ind_obj, reindex=reindex)
                    if _Debug:
                        lg.out(_DebugLevel, '        updated index %s' % ind)
                except:
                    lg.exc('failed rewriting index "%r"' % ind)
                    ok = False
                    break
    return ok