chromium-dashboard/api/channels_api.py

124 строки
3.9 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2021 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import json
import requests
from framework import basehandlers
from framework import rediscache
from internals import fetchchannels
import settings
SCHEDULE_CACHE_TIME = 60 * 60 # 1 hour
def construct_chrome_channels_details():
omaha_data = fetchchannels.get_omaha_data()
channels = {}
win_versions = omaha_data[0]['versions']
for v in win_versions:
channel = v['channel']
major_version = int(v['version'].split('.')[0])
channels[channel] = fetch_chrome_release_info(major_version)
channels[channel]['version'] = major_version
# Adjust for the brief period after next miletone gets promted to stable/beta
# channel and their major versions are the same.
if channels['stable']['version'] == channels['beta']['version']:
new_beta_version = channels['stable']['version'] + 1
channels['beta'] = fetch_chrome_release_info(new_beta_version)
channels['beta']['version'] = new_beta_version
if channels['beta']['version'] == channels['dev']['version']:
new_dev_version = channels['beta']['version'] + 1
channels['dev'] = fetch_chrome_release_info(new_dev_version)
channels['dev']['version'] = new_dev_version
# In the situation where some versions are in a gap between
# stable and beta, show one as 'stable_soon'.
if channels['stable']['version'] + 1 < channels['beta']['version']:
stable_soon_version = channels['stable']['version'] + 1
channels['stable_soon'] = fetch_chrome_release_info(stable_soon_version)
channels['stable_soon']['version'] = stable_soon_version
return channels
def fetch_chrome_release_info(version):
key = 'chromerelease|%s' % version
data = rediscache.get(key)
if data is None:
url = ('https://chromiumdash.appspot.com/fetch_milestone_schedule?'
'mstone=%s' % version)
result = requests.get(url, timeout=60)
if result.status_code == 200:
try:
logging.info(
'result.content is:\n%s', result.content[:settings.MAX_LOG_LINE])
result_json = json.loads(result.content)
if 'mstones' in result_json:
data = result_json['mstones'][0]
del data['owners']
del data['feature_freeze']
del data['ldaps']
rediscache.set(key, data, time=SCHEDULE_CACHE_TIME)
except ValueError:
pass # Handled by next statement
if not data:
data = {
'stable_date': None,
'earliest_beta': None,
'latest_beta': None,
'mstone': version,
'version': version,
}
# Note: we don't put placeholder data into redis.
return data
def construct_specified_milestones_details(start, end):
channels = {}
win_versions = list(range(start,end+1))
for milestone in win_versions:
channels[milestone] = fetch_chrome_release_info(milestone)
return channels
class ChannelsAPI(basehandlers.APIHandler):
"""Channels are the Chrome Versions across platforms."""
def do_get(self, **kwargs):
# Query-string parameters 'start' and 'end' are provided
start = self.get_int_arg('start')
end = self.get_int_arg('end')
if start is None or end is None:
return construct_chrome_channels_details()
if start > end:
raise ValueError
return construct_specified_milestones_details(start, end)
# TODO(jrobbins): do_post
# TODO(jrobbins): do_patch