Chromium Code Reviews| Index: build/android/gyp/java_google_api_keys.py |
| diff --git a/build/android/gyp/java_google_api_keys.py b/build/android/gyp/java_google_api_keys.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..8596e84f38205ac74d14841eb3a6a05c0d631189 |
| --- /dev/null |
| +++ b/build/android/gyp/java_google_api_keys.py |
| @@ -0,0 +1,94 @@ |
| +#!/usr/bin/env python |
| +# |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +# Generates a Java file with API keys. |
| + |
| +import argparse |
| +import os |
| +import string |
| +import sys |
| + |
| +sys.path.append( |
| + os.path.abspath(os.path.join(sys.path[0], '../../../google_apis'))) |
| +from google_api_keys import (GetAPIKey, GetAPIKeyRemoting, GetClientID, |
|
agrieve
2015/11/03 16:22:42
Don't import functions.
dvh
2015/11/03 20:03:54
Done.
|
| + GetClientSecret) |
| + |
| + |
| +def GetScriptName(): |
| + script_components = os.path.abspath(sys.argv[0]).split(os.path.sep) |
| + build_index = script_components.index('build') |
|
agrieve
2015/11/03 16:22:42
use constants.DIR_SOURCE_ROOT
dvh
2015/11/03 20:03:54
Done.
|
| + return os.sep.join(script_components[build_index:]) |
| + |
|
agrieve
2015/11/03 16:22:42
2 blank lines
dvh
2015/11/03 20:03:54
Done.
|
| +def GenerateOutput(constant_definitions): |
| + template = string.Template(""" |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// This file is autogenerated by |
| +// ${SCRIPT_NAME} |
| +// From |
| +// ${SOURCE_PATH} |
| + |
| +package ${PACKAGE}; |
| + |
| +public class ${CLASS_NAME} { |
| +${CONSTANT_ENTRIES} |
| +} |
| +""") |
| + |
| + |
| + constant_template = string.Template( |
| + ' public static final String ${NAME} = "${VALUE}";') |
| + constant_entries_list = [] |
| + for constant_name, constant_value in constant_definitions.iteritems(): |
| + values = { |
| + 'NAME': constant_name, |
| + 'VALUE': constant_value, |
| + } |
| + constant_entries_list.append(constant_template.substitute(values)) |
| + constant_entries_string = '\n'.join(constant_entries_list) |
| + |
| + values = { |
| + 'CLASS_NAME': 'GoogleAPIKeys', |
| + 'CONSTANT_ENTRIES': constant_entries_string, |
| + 'PACKAGE': 'org.chromium.chrome', |
| + 'SCRIPT_NAME': GetScriptName(), |
| + 'SOURCE_PATH': 'google_api_keys/google_api_keys.h', |
| + } |
| + return template.substitute(values) |
| + |
| +def _DoWriteOutput(output_path, constant_definition): |
| + folder = os.path.dirname(output_path) |
| + if not os.path.exists(folder): |
| + os.makedirs(folder) |
| + with open(output_path, 'w') as out_file: |
| + out_file.write(GenerateOutput(constant_definition)) |
| + |
| +def _DoMain(argv): |
| + parser = argparse.ArgumentParser() |
| + parser.add_argument("--out", help="Output file.", required=True) |
| + options = parser.parse_args(argv) |
| + |
| + values = {} |
| + values['GOOGLE_API_KEY'] = GetAPIKey() |
| + values['GOOGLE_API_KEY_REMOTING'] = GetAPIKeyRemoting() |
| + values['GOOGLE_CLIENT_ID_MAIN'] = GetClientID('MAIN') |
| + values['GOOGLE_CLIENT_SECRET_MAIN'] = GetClientSecret('MAIN') |
| + values['GOOGLE_CLIENT_ID_CLOUD_PRINT'] = GetClientID('CLOUD_PRINT') |
| + values['GOOGLE_CLIENT_SECRET_CLOUD_PRINT'] = GetClientSecret('CLOUD_PRINT') |
| + values['GOOGLE_CLIENT_ID_REMOTING'] = GetClientID('REMOTING') |
| + values['GOOGLE_CLIENT_SECRET_REMOTING'] = GetClientSecret('REMOTING') |
| + values['GOOGLE_CLIENT_ID_REMOTING_HOST'] = GetClientID('REMOTING_HOST') |
| + values['GOOGLE_CLIENT_SECRET_REMOTING_HOST'] = GetClientSecret( |
| + 'REMOTING_HOST') |
| + values['GOOGLE_CLIENT_ID_REMOTING_IDENTITY_API'] = GetClientID( |
| + 'REMOTING_IDENTITY_API') |
| + _DoWriteOutput(options.out, values) |
| + |
| +if __name__ == '__main__': |
| + _DoMain(sys.argv[1:]) |
| + |