original_docstring: 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.
      
docstring: 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.
docstring_tokens: 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 .
code: 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
      index_yaml_file = os.path.join(self._root_path, 'index.yaml')
      if (self._cached_yaml[0] == index_yaml_file and
          os.path.exists(index_yaml_file) and
          os.path.getmtime(index_yaml_file) == self._cached_yaml[1]):
        requested_indexes = self._cached_yaml[2]
      else:
        try:
          index_yaml_mtime = os.path.getmtime(index_yaml_file)
          fh = _open(index_yaml_file, 'r')
        except (OSError, IOError):
          index_yaml_data = None
        else:
          try:
            index_yaml_data = fh.read()
          finally:
            fh.close()
  
        requested_indexes = []
        if index_yaml_data is not None:
  
          index_defs = datastore_index.ParseIndexDefinitions(index_yaml_data)
          if index_defs is not None and index_defs.indexes is not None:
  
            requested_indexes = datastore_index.IndexDefinitionsToProtos(
                self._app_id,
                index_defs.indexes)
            self._cached_yaml = (index_yaml_file, index_yaml_mtime,
                                 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 key not in requested:
          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))
code_tokens: def _SetupIndexes ( self , _open = open ) : if not self . _root_path : return index_yaml_file = os . path . join ( self . _root_path , 'index.yaml' ) if ( self . _cached_yaml [ 0 ] == index_yaml_file and os . path . exists ( index_yaml_file ) and os . path . getmtime ( index_yaml_file ) == self . _cached_yaml [ 1 ] ) : requested_indexes = self . _cached_yaml [ 2 ] else : try : index_yaml_mtime = os . path . getmtime ( index_yaml_file ) fh = _open ( index_yaml_file , 'r' ) except ( OSError , IOError ) : index_yaml_data = None else : try : index_yaml_data = fh . read ( ) finally : fh . close ( ) requested_indexes = [ ] if index_yaml_data is not None : index_defs = datastore_index . ParseIndexDefinitions ( index_yaml_data ) if index_defs is not None and index_defs . indexes is not None : requested_indexes = datastore_index . IndexDefinitionsToProtos ( self . _app_id , index_defs . indexes ) self . _cached_yaml = ( index_yaml_file , index_yaml_mtime , 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 key not in requested : 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 ) )
short_docstring: Ensure that the set of existing composite indexes matches index.yaml.
short_docstring_tokens: Ensure that the set of existing composite indexes matches index . yaml .
comment: """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.
      """