Example #1
0
def show_all_flakes(flake, bug_friendly):
  occurrence_keys = []
  for o in flake.occurrences:
    occurrence_keys.append(o)

  occurrences = ndb.get_multi(occurrence_keys)

  failure_runs_keys = []
  patchsets_keys = []
  for o in occurrences:
    failure_runs_keys.append(o.failure_run)
    patchsets_keys.append(o.failure_run.parent())

  failure_runs = ndb.get_multi(failure_runs_keys)
  patchsets = ndb.get_multi(patchsets_keys)

  pst_timezone = pytz.timezone("US/Pacific")
  for index, f in enumerate(failure_runs):
    f.patchset_url = patchsets[index].getURL()
    f.builder = patchsets[index].builder
    f.formatted_time = f.time_finished.replace(tzinfo=pytz.utc).astimezone(
        pst_timezone).strftime('%m/%d/%y %I:%M %p')

  # Do simple sorting to make reading easier.
  failure_runs = sorted(failure_runs, key=RunsSortFunction)

  values = {
    'flake': flake,
    'failure_runs': failure_runs,
    'bug_friendly': bug_friendly,
    'time_now': datetime.datetime.now(),
  }

  return template.render('templates/all_flake_occurrences.html', values)
Example #2
0
    def get(self):
        time_range = self.request.get('range', default_value='day')
        cursor = Cursor(urlsafe=self.request.get('cursor'))
        flakes_query = Flake.query()
        if time_range == 'hour':
            flakes_query = flakes_query.filter(Flake.last_hour == True)
            flakes_query = flakes_query.order(-Flake.count_hour)
        elif time_range == 'day':
            flakes_query = flakes_query.filter(Flake.last_day == True)
            flakes_query = flakes_query.order(-Flake.count_day)
        elif time_range == 'week':
            flakes_query = flakes_query.filter(Flake.last_week == True)
            flakes_query = flakes_query.order(-Flake.count_week)
        elif time_range == 'month':
            flakes_query = flakes_query.filter(Flake.last_month == True)
            flakes_query = flakes_query.order(-Flake.count_month)
        else:
            flakes_query = flakes_query.order(-Flake.count_all)

        flakes_query = flakes_query.order(-Flake.last_time_seen)
        flakes, next_cursor, more = flakes_query.fetch_page(
            10, start_cursor=cursor)

        # Filter out occurrences so that we only show ones for the selected time
        # range. This is less confusing to read, and also less cluttered and renders
        # faster when not viewing all range.
        for f in flakes:
            # get_multi is much faster than calling .get for each f.occurrences
            occurrences = ndb.get_multi(f.occurrences)

            failure_run_keys = []
            patchsets_keys = []
            for o in occurrences:
                failure_run_keys.append(o.failure_run)
                patchsets_keys.append(o.failure_run.parent())

            failure_runs = ndb.get_multi(failure_run_keys)
            patchsets = ndb.get_multi(patchsets_keys)

            f.filtered_occurrences = []
            # tryserver pages show PST time so do so here as well for easy comparison.
            pst_timezone = pytz.timezone("US/Pacific")
            for index, r in enumerate(failure_runs):
                if (time_range == 'hour' and is_last_hour(r.time_finished)) or \
                   (time_range == 'day' and is_last_day(r.time_finished)) or \
                   (time_range == 'week' and is_last_week(r.time_finished)) or \
                   (time_range == 'month' and is_last_month(r.time_finished)) or \
                   time_range == 'all':
                    r.patchset_url = patchsets[index].getURL()
                    r.builder = patchsets[index].builder

                    time_format = ''
                    if time_range == 'hour':
                        time_format = '%I:%M %p'
                    elif (time_range == 'day' or time_range == 'week'
                          or time_range == 'month'):
                        time_format = '%m/%d %I:%M %p'
                    else:
                        time_format = '%m/%d/%y %I:%M %p'
                    r.formatted_time = r.time_finished.replace(tzinfo=pytz.utc). \
                        astimezone(pst_timezone).strftime(time_format)
                    f.filtered_occurrences.append(r)

            # Do simple sorting of occurances by builder to make reading easier.
            f.filtered_occurrences = sorted(f.filtered_occurrences,
                                            key=FlakeSortFunction)

        values = {
            'range': time_range,
            'flakes': flakes,
            'more': more,
            'cursor': next_cursor.urlsafe() if next_cursor else '',
        }
        self.response.write(template.render('templates/index.html', values))
Example #3
0
  def get(self):
    time_range = self.request.get('range', default_value='day')
    cursor = Cursor(urlsafe=self.request.get('cursor'))
    flakes_query = Flake.query()
    if time_range == 'hour':
      flakes_query = flakes_query.filter(Flake.last_hour == True)
      flakes_query = flakes_query.order(-Flake.count_hour)
    elif time_range == 'day':
      flakes_query = flakes_query.filter(Flake.last_day == True)
      flakes_query = flakes_query.order(-Flake.count_day)
    elif time_range == 'week':
      flakes_query = flakes_query.filter(Flake.last_week == True)
      flakes_query = flakes_query.order(-Flake.count_week)
    elif time_range == 'month':
      flakes_query = flakes_query.filter(Flake.last_month == True)
      flakes_query = flakes_query.order(-Flake.count_month)
    else:
      flakes_query = flakes_query.order(-Flake.count_all)

    flakes_query = flakes_query.order(-Flake.last_time_seen)
    flakes, next_cursor, more = flakes_query.fetch_page(10, start_cursor=cursor)

    # Filter out occurrences so that we only show ones for the selected time
    # range. This is less confusing to read, and also less cluttered and renders
    # faster when not viewing all range.
    for f in flakes:
      # get_multi is much faster than calling .get for each f.occurrences
      occurrences = ndb.get_multi(f.occurrences)

      failure_run_keys = []
      patchsets_keys = []
      for o in occurrences:
        failure_run_keys.append(o.failure_run)
        patchsets_keys.append(o.failure_run.parent())

      failure_runs = ndb.get_multi(failure_run_keys)
      patchsets = ndb.get_multi(patchsets_keys)

      f.filtered_occurrences = []
      # tryserver pages show PST time so do so here as well for easy comparison.
      pst_timezone = pytz.timezone("US/Pacific")
      for index, r in enumerate(failure_runs):
        if (time_range == 'hour' and is_last_hour(r.time_finished)) or \
           (time_range == 'day' and is_last_day(r.time_finished)) or \
           (time_range == 'week' and is_last_week(r.time_finished)) or \
           (time_range == 'month' and is_last_month(r.time_finished)) or \
           time_range == 'all':
          r.patchset_url = patchsets[index].getURL()
          r.builder = patchsets[index].builder

          time_format = ''
          if time_range == 'hour':
            time_format = '%I:%M %p'
          elif (time_range == 'day' or time_range == 'week' or
                time_range == 'month'):
            time_format = '%m/%d %I:%M %p'
          else:
            time_format = '%m/%d/%y %I:%M %p'
          r.formatted_time = r.time_finished.replace(tzinfo=pytz.utc). \
              astimezone(pst_timezone).strftime(time_format)
          f.filtered_occurrences.append(r)

      # Do simple sorting of occurances by builder to make reading easier.
      f.filtered_occurrences = sorted(f.filtered_occurrences,
                                      key=FlakeSortFunction)

    values = {
      'range': time_range,
      'flakes': flakes,
      'more': more,
      'cursor': next_cursor.urlsafe() if next_cursor else '',
    }
    self.response.write(template.render('templates/index.html', values))
Example #4
0
def _now_us_pacific():
    """Get the current date, in US/Pacific time."""
    # Late import so that we can avoid this in tests.
    from third_party.pytz.gae import pytz
    return datetime.datetime.now(pytz.timezone('US/Pacific'))