def GetAutoPromoteDate(track, applesus_product):
  """Returns a date of when a given update will auto-promote.

  Args:
    track: str track to get the auto-promote datetime for.
    applesus_product: models.AppleSUSProduct object.
  Returns:
    datetime.date of when the Apple SUS update will be auto-promoted to track,
    or None if the product will never be auto-promoted due to manual_override or
    the product not being in the unstable track.
  Raises:
    ValueError: an invalid track was specified; only testing/stable supported.
  """
  if not settings.APPLE_AUTO_PROMOTE_ENABLED:
    return None
  if applesus_product.manual_override:
    return None
  elif common.UNSTABLE not in applesus_product.tracks:
    return None

  if track == common.TESTING:
    days = settings.APPLE_UNSTABLE_GRACE_PERIOD_DAYS
  elif track == common.STABLE:
    days = settings.APPLE_TESTING_GRACE_PERIOD_DAYS
  else:
    raise ValueError('Invalid track was specified: %s' % track)

  auto_promote_offset = datetime.timedelta(days=days)
  previous_track_date = applesus_product.mtime.date()

  if track == common.TESTING:
    auto_promote_date = previous_track_date + auto_promote_offset
    if auto_promote_date.weekday() >= SAT:  # Sat or Sun.
      auto_promote_date = _GetNextWeekdayDate(
          weekday=MON, min_date=auto_promote_date)
    return auto_promote_date

  # If we're looking for a stable auto-promotion date but the item is not yet in
  # testing, then we need to first figure out when it will go to testing and set
  # the previous_track_mtime to that.
  if common.TESTING not in applesus_product.tracks:
    previous_track_date = GetAutoPromoteDate('testing', applesus_product)

  # Unstable should only promoted on Wednesdays and only after the grace period.
  min_auto_promote_date = previous_track_date + auto_promote_offset
  return _GetNextWeekdayDate(
      weekday=settings.APPLE_AUTO_PROMOTE_STABLE_WEEKDAY,
      min_date=min_auto_promote_date)
dataset/ETHPy150Open google/simian/src/simian/mac/common/applesus.py/GetAutoPromoteDate/original