def MigrateHuntFinishedAndErrors(hunt_or_urn, token=None):
  if hasattr(hunt_or_urn, "Schema"):
    hunt = hunt_or_urn
    if hunt.age_policy != aff4.ALL_TIMES:
      raise RuntimeError("Hunt object should have ALL_TIMES age policy.")
  else:
    hunt = aff4.FACTORY.Open(hunt_or_urn, aff4_type="GRRHunt", token=token,
                             age=aff4.ALL_TIMES)

  print "Migrating hunt %s." % hunt.urn

  print "Processing all clients list."
  aff4.FACTORY.Delete(hunt.all_clients_collection_urn, token=token)
  with aff4.FACTORY.Create(hunt.all_clients_collection_urn,
                           aff4_type="PackedVersionedCollection",
                           mode="w", token=token) as all_clients_collection:
    clients = set(hunt.GetValuesForAttribute(hunt.Schema.DEPRECATED_CLIENTS))
    for client in reversed(sorted(clients, key=lambda x: x.age)):
      all_clients_collection.Add(client)

  print "Processing completed clients list."
  aff4.FACTORY.Delete(hunt.completed_clients_collection_urn, token=token)
  with aff4.FACTORY.Create(hunt.completed_clients_collection_urn,
                           aff4_type="PackedVersionedCollection",
                           mode="w", token=token) as comp_clients_collection:
    clients = set(hunt.GetValuesForAttribute(hunt.Schema.DEPRECATED_FINISHED))
    for client in reversed(sorted(clients, key=lambda x: x.age)):
      comp_clients_collection.Add(client)

  print "Processing errors list."
  aff4.FACTORY.Delete(hunt.clients_errors_collection_urn, token=token)
  with aff4.FACTORY.Create(hunt.clients_errors_collection_urn,
                           aff4_type="PackedVersionedCollection",
                           mode="w", token=token) as errors_collection:
    for error in hunt.GetValuesForAttribute(hunt.Schema.DEPRECATED_ERRORS):
      errors_collection.Add(error)
Migrates given hunt to collection-stored clients/errors lists.
dataset/ETHPy150Open google/grr/grr/lib/console_utils.py/MigrateHuntFinishedAndErrors