def _RetrieveTreeStatus(tree_name, start_time, end_time=None): """Returns a time-ascending-sorted TreeStatus list since checking point.""" url = _MONITORED_TREES[tree_name] params = { 'limit': 1000, # 1000 is large enough to get all recent tree statuses. 'format': 'json', # Tree status app treats endTime as the beginning of the time range. 'endTime': time_util.ConvertToTimestamp(start_time), } if end_time: # Tree status app treats startTime as the end of the time range. params['startTime'] = time_util.ConvertToTimestamp(end_time) http_client = FinditHttpClient() status_code, content, _response_headers = http_client.Get(url, params=params) if status_code == 200: all_statuses = map(_CreateTreeStatus, json.loads(content)) all_statuses.sort(key=lambda s: s.time) # With 'endTime' set, the Tree status app always includes a duplicate entry # for the latest status. return all_statuses[:-1] else: logging.error('Failed to retrieve tree status for %s from %r to %r', tree_name, start_time, end_time) return [] # Wait for next execution.
def _TreeIsOpen(): """Determine whether the chromium tree is currently open.""" url = 'https://chromium-status.appspot.com/allstatus' params = { 'limit': '1', 'format': 'json', } client = FinditHttpClient() status_code, content, _response_headers = client.Get(url, params) if status_code == 200: try: states = json.loads(str(content)) if states and states[0].get('general_state') == 'open': return True except ValueError, ve: logging.exception('Could not parse chromium tree status: %s', ve)