def _SetupIndexes(self, _open=open):
    """Ensure that the set of existing composite indexes matches index.yaml.

    Note: this is similar to the algorithm used by the admin console for
    the same purpose.
    """



    if not self._root_path:
      return
    file_names = [os.path.join(self._root_path, 'index.yaml')]
    file_mtimes = [os.path.getmtime(f) for f in file_names if os.path.exists(f)]
    if (self._cached_index_definitions.file_names == file_names and
        all(os.path.exists(f) for f in file_names) and
        self._cached_index_definitions.last_modifieds == file_mtimes):
      requested_indexes = self._cached_index_definitions.index_protos
    else:
      file_mtimes = []
      index_texts = []
      for file_name in file_names:
        try:
          file_mtimes.append(os.path.getmtime(file_name))
          with _open(file_name, 'r') as fh:
            index_texts.append(fh.read())
        except (OSError, IOError):
          pass

      requested_indexes = []
      if len(index_texts) == len(file_names):
        all_ok = True
        for index_text in index_texts:

          index_defs = datastore_index.ParseIndexDefinitions(index_text)
          if index_defs is None or index_defs.indexes is None:
            all_ok = False
          else:

            requested_indexes.extend(
                datastore_index.IndexDefinitionsToProtos(
                    self._app_id, index_defs.indexes))
        if all_ok:
          self._cached_index_definitions = _CachedIndexDefinitions(
              file_names, file_mtimes, requested_indexes)


    existing_indexes = self._datastore.GetIndexes(
        self._app_id, self._trusted, self._app_id)


    requested = dict((x.definition().Encode(), x) for x in requested_indexes)
    existing = dict((x.definition().Encode(), x) for x in existing_indexes)


    created = 0
    for key, index in requested.iteritems():
      if key not in existing:
        new_index = entity_pb.CompositeIndex()
        new_index.CopyFrom(index)
        new_index.set_id(datastore_admin.CreateIndex(new_index))
        new_index.set_state(entity_pb.CompositeIndex.READ_WRITE)
        datastore_admin.UpdateIndex(new_index)
        created += 1


    deleted = 0
    for key, index in existing.iteritems():
      if requested not in key:
        datastore_admin.DeleteIndex(index)
        deleted += 1


    if created or deleted:
      logging.debug('Created %d and deleted %d index(es); total %d',
                    created, deleted, len(requested))
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/datastore/datastore_stub_util.py/DatastoreStub._SetupIndexes/swapped operands of `not in`