Ejemplo n.º 1
0
    def map(self, key):
        """Copy data map handler.

    Args:
      key: Datastore entity key or entity itself to copy.

    Yields:
      A db operation to store the entity in the target app.
      An operation which updates max used ID if necessary.
      A counter operation incrementing the count for the entity kind.
    """

        mapper_params = get_mapper_params()
        target_app = mapper_params['target_app']

        if isinstance(key, datastore.Entity):

            entity = key
            key = entity.key()
        else:
            entity = datastore.Get(key)
        entity_proto = entity._ToPb()
        utils.FixKeys(entity_proto, target_app)
        target_entity = datastore.Entity._FromPb(entity_proto)

        yield operation.db.Put(target_entity)
        yield utils.AllocateMaxId(key, target_app)
        yield operation.counters.Increment(KindPathFromKey(key))
Ejemplo n.º 2
0
  def map(self, record):
    """Restore entity map handler.

    Args:
      record: A serialized entity_pb.EntityProto.

    Yields:
      A operation.db.Put for the mapped entity
    """
    self.initialize()
    pb = entity_pb.EntityProto(contents=record)
    if self.app_id:
      utils.FixKeys(pb, self.app_id)
    entity = datastore.Entity.FromPb(pb)
    if not self.kind_filter or entity.kind() in self.kind_filter:
      yield op.db.Put(entity)
      if self.app_id:
        yield utils.AllocateMaxId(entity.key(), self.app_id)