From b37b10e669b3c87f2fa91756ecc22623464f661b Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Thu, 8 Apr 2021 08:27:30 -0700 Subject: [PATCH] Restandardize chromehistory columns; fix chromepolicy (#1362) * Restandardize chromehistory columns; fix chromepolicy * Update chromehistory.py --- src/gam/gapi/chromehistory.py | 26 +++++++++++++++----------- src/gam/gapi/chromepolicy.py | 7 ++++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/gam/gapi/chromehistory.py b/src/gam/gapi/chromehistory.py index 6d8e4799..99ed9207 100644 --- a/src/gam/gapi/chromehistory.py +++ b/src/gam/gapi/chromehistory.py @@ -43,11 +43,11 @@ CHROME_VERSIONHISTORY_ORDERBY_CHOICE_MAP = { CHROME_VERSIONHISTORY_TITLES = { 'platforms': ['platform'], 'channels': ['channel', 'platform'], - 'versions': ['version', 'platform', 'channel', + 'versions': ['version', 'channel', 'platform', 'major_version', 'minor_version', 'build', 'patch'], - 'releases': ['version', 'fraction', 'serving.startTime', - 'serving.endTime', 'platform', 'channel', - 'major_version', 'minor_version', 'build', 'patch'] + 'releases': ['version', 'channel', 'platform', + 'major_version', 'minor_version', 'build', 'patch', + 'fraction', 'serving.startTime','serving.endTime'] } def get_relative_milestone(channel='stable', minus=0): @@ -76,22 +76,26 @@ def get_relative_milestone(channel='stable', minus=0): except IndexError: return '' -def _get_platform_map(cv): +def get_platform_map(cv=None): '''returns dict mapping of platform choices''' + if cv is None: + cv = build() result = gapi.get_all_pages(cv.platforms(), 'list', 'platforms', parent='chrome') platforms = [p.get('platformType', '').lower() for p in result] platform_map = {'all': 'all'} - for platform in platforms: - key = platform.replace('_', '') - platform_map[key] = platform + for cplatform in platforms: + key = cplatform.replace('_', '') + platform_map[key] = cplatform return platform_map -def _get_channel_map(cv): +def get_channel_map(cv=None): '''returns dict mapping of channel choices''' + if cv is None: + cv = build() result = gapi.get_all_pages(cv.platforms().channels(), 'list', 'channels', @@ -125,7 +129,7 @@ def printHistory(): i += 1 elif entityType != 'platforms' and myarg == 'platform': cplatform = sys.argv[i + 1].lower().replace('_', '') - platform_map = _get_platform_map(cv) + platform_map = get_platform_map(cv) if cplatform not in platform_map: controlflow.expected_argument_exit('platform', ', '.join(platform_map), @@ -134,7 +138,7 @@ def printHistory(): i += 2 elif entityType in {'versions', 'releases'} and myarg == 'channel': channel = sys.argv[i + 1].lower().replace('_', '') - channel_map = _get_channel_map(cv) + channel_map = get_channel_map(cv) if channel not in channel_map: controlflow.expected_argument_exit('channel', ', '.join(channel_map), diff --git a/src/gam/gapi/chromepolicy.py b/src/gam/gapi/chromepolicy.py index f8ffeb1e..679d373a 100644 --- a/src/gam/gapi/chromepolicy.py +++ b/src/gam/gapi/chromepolicy.py @@ -306,13 +306,14 @@ def update_policy(): if mg: channel = mg.group(1).lower().replace('_', '') minus = mg.group(2) - if channel not in gapi_chromehistory.CHROME_CHANNEL_CHOICE_MAP: - expected_channels = ', '.join(gapi_chromehistory.CHROME_CHANNEL_CHOICE_MAP) + channel_map = gapi_chromehistory.get_channel_map(None) + if channel not in channel_map: + expected_channels = ', '.join(channel_map) msg = f'Expected {myarg} {cased_field} channel to be one of ' \ f'{expected_channels}, got {channel}' controlflow.system_error_exit(8, msg) milestone = gapi_chromehistory.get_relative_milestone( - gapi_chromehistory.CHROME_CHANNEL_CHOICE_MAP[channel], int(minus)) + channel_map[channel], int(minus)) if not milestone: msg = f'{myarg} {cased_field} channel {channel} offset {minus} does not exist' controlflow.system_error_exit(8, msg)