blob: da1215564c671df4a7355d511bb92e5d70201a0d [file] [log] [blame]
#!/usr/bin/env python2
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Updates testdata/ based on data pulled from Chromium sources."""
from __future__ import print_function
import argparse
import base64
import json
# pylint: disable=cros-logging-import
import logging
import os
import re
import subprocess
import sys
import yaml
# URLs to GIT paths.
TESTDATA_PATH = os.path.join(os.path.dirname(__file__), 'testdata')
def GetChromiumSource(file_path):
"""Gets Chromium source code by given path.
file_path: The relative path to retrieve.
return base64.b64decode(subprocess.check_output(
['curl', '-s', SRC_GIT_URL + file_path + '?format=TEXT']))
def WriteTestData(name, value):
if not value:
sys.exit('No values found for %s' % name)
path = os.path.join(TESTDATA_PATH, name + '.yaml')'%s: writing %r', path, value)
with open(path, 'w') as f:
f.write('# Automatically generated from ToT Chromium sources\n'
'# by Do not edit manually.\n'
yaml.dump(value, f, default_flow_style=False)
def UpdateLocales():
"""Updates locales.
Valid locales are entries of the kAcceptLanguageList array in <>.
cpp_code = GetChromiumSource('ui/base/l10n/')
match ='static[^\n]+kAcceptLanguageList\[\] = \{(.+?)^\}',
cpp_code, re.DOTALL | re.MULTILINE)
if not match:
sys.exit('Unable to find language list')
locales = re.findall(r'"(.+)"',
if not locales:
sys.exit('Unable to parse language list')
WriteTestData('locales', sorted(locales))
def UpdateTimeZones():
"""Updates time zones.
Valid time zones are values of the kTimeZones array in
cpp_code = GetChromiumSource('chromeos/settings/')
match ='static[^\n]+kTimeZones\[\] = \{(.+?)^\}',
cpp_code, re.DOTALL | re.MULTILINE)
if not match:
sys.exit('Unable to find time zones')
time_zones = re.findall(r'"(.+)"',
if not time_zones:
sys.exit('Unable to parse time zones')
WriteTestData('time_zones', time_zones)
def UpdateMigrationMap():
"""Updates the input method migration map.
The source is the kEngineIdMigrationMap array in
cpp_code = GetChromiumSource('ui/base/ime/chromeos/')
match ='kEngineIdMigrationMap\[\]\[2\] = \{(.+?)^\}',
cpp_code, re.DOTALL | re.MULTILINE)
if not match:
sys.exit('Unable to find kEngineIdMigrationMap')
map_code =
migration_map = re.findall(r'{"(.+?)", "(.+?)"}', map_code)
if not migration_map:
sys.exit('Unable to parse kEngineIdMigrationMap')
WriteTestData('migration_map', migration_map)
def UpdateInputMethods():
"""Updates input method IDs.
This is the union of all 'id' fields in input_method/*.json
# entry format: 100644 blob 48de6e64885e472c6743543cc988ac0fd8edd55e FILE
json_dir = 'chrome/browser/resources/chromeos/input_method'
files = [line.strip().split()[-1]
for line in GetChromiumSource(json_dir).splitlines()]
pattern = re.compile(r'\.json$')
json_files = [f for f in files if]
input_methods = set()
for f in json_files:
contents = json.loads(GetChromiumSource(os.path.join(json_dir, f)))
for c in contents['input_components']:
WriteTestData('input_methods', sorted(input_methods))
def main():
parser = argparse.ArgumentParser(
description=('Updates some constants in based '
'on data pulled from Chromium sources. This overwrites '
'files in testdata, which you must then submit.'))
unused_args = parser.parse_args()
UpdateMigrationMap()'Run "git diff %s" to see changes (if any).', TESTDATA_PATH)'Make sure to submit any changes to %s!', TESTDATA_PATH)
if __name__ == '__main__':