Пример #1
0
def make_catalog(uri, fields):
    """Creates a new and empty catalog in the given uri.

    fields must be a dict. It contains some informations about the
    fields in the database. It must contain at least the abspath key field.

    For example:

      fields = {'abspath': String(stored=True, indexed=True),
                'name': Unicode(indexed=True), ...}
    """
    path = lfs.get_absolute_path(uri)
    db = WritableDatabase(path, DB_CREATE)
    return Catalog(db, fields)
Пример #2
0
    def __init__(self,
                 ref,
                 fields,
                 read_only=False,
                 asynchronous_mode=True,
                 root=None):
        self.read_only = read_only
        # Load the database
        if isinstance(ref, (Database, WritableDatabase)):
            path = None
            self._db = ref
        else:
            path = lfs.get_absolute_path(ref)
            if read_only:
                self._db = Database(path)
            else:
                self._db = WritableDatabase(path, DB_OPEN)

        db = self._db
        self._asynchronous = asynchronous_mode
        self._fields = fields
        self.root = root
        # FIXME: There's a bug in xapian:
        # Wa cannot get stored values if DB not flushed
        #self.commit_each_transaction = root is None
        self.commit_each_transaction = True
        # Asynchronous mode
        if not read_only and asynchronous_mode:
            db.begin_transaction(self.commit_each_transaction)
        # Set XAPIAN_FLUSH_THRESHOLD
        os.environ["XAPIAN_FLUSH_THRESHOLD"] = "2000"
        # Load the xfields from the database
        self._metadata = {}
        self._value_nb = 0
        self._prefix_nb = 0
        self.transaction_abspaths = []
        self._load_all_internal()
        if not read_only:
            self._init_all_metadata()
        # Catalog log
        if path:
            catalog_log = '{}/catalog.log'.format(path)
            self.logger = CatalogLogger(catalog_log)
            register_logger(self.logger, 'itools.catalog')
Пример #3
0
 def open_index(self, temp_path=False):
     # callers to open_index must be able to
     # handle an exception -- usually caused by
     # IO errors such as ENOSPC and retry putting
     # the index on a temp_path
     if temp_path:
         try:
             # mark the on-disk index stale
             self._set_index_updated(False)
         except:
             pass
         self._index_path = temp_path
     else:
         self._index_path = self._std_index_path
     try:
         self._database = WritableDatabase(self._index_path,
                                           xapian.DB_CREATE_OR_OPEN)
     except Exception as e:
         logging.error('Exception opening database')
         raise
Пример #4
0
    def __init__(self, ref, fields, read_only=False, asynchronous_mode=True):
        # Load the database
        if isinstance(ref, (Database, WritableDatabase)):
            self._db = ref
        else:
            path = lfs.get_absolute_path(ref)
            if read_only:
                self._db = Database(path)
            else:
                self._db = WritableDatabase(path, DB_OPEN)

        db = self._db
        self._asynchronous = asynchronous_mode
        self._fields = fields

        # Asynchronous mode
        if not read_only and asynchronous_mode:
            db.begin_transaction(False)

        # Load the xfields from the database
        self._metadata = {}
        self._value_nb = 0
        self._prefix_nb = 0
        self._load_all_internal()