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..e95b43ebeb0e032cc24988b61dba41b9b56f12c2 |
| --- /dev/null |
| +++ b/build/android/gyp/java_google_api_keys.py |
| @@ -0,0 +1,84 @@ |
| +#!/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 os |
| +from string import Template |
|
agrieve
2015/10/30 00:55:13
style guide is against importing classes (here and
dvh
2015/10/30 20:56:20
Done.
agrieve
2015/10/31 02:09:37
Please fix all imports that do this (google_apk_ke
|
| +import sys |
| + |
| +sys.path.append( |
| + os.path.abspath(os.path.join(sys.path[0], '../../../google_apis'))) |
| +from google_api_keys import (GetAPIKey, GetAPIKeyRemoting, GetClientID, |
| + GetClientSecret) |
| + |
|
agrieve
2015/10/30 00:55:13
two lines between top-level declarations
dvh
2015/10/30 20:56:20
Done.
|
| +def GetScriptName(): |
|
agrieve
2015/10/30 00:55:13
I think this function would be better to use:
o
agrieve
2015/10/30 00:55:13
Make this private (_GetScriptName)
dvh
2015/10/30 20:56:20
It's exported for the unit test.
dvh
2015/10/30 20:56:20
constants didn't work. I tried to import it. It ha
agrieve
2015/10/31 02:09:37
You need to tweak the sys.path (not a great practi
|
| + script_components = os.path.abspath(sys.argv[0]).split(os.path.sep) |
| + build_index = script_components.index('build') |
| + return os.sep.join(script_components[build_index:]) |
| + |
| +def GenerateOutput(constant_definitions): |
| + template = 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 = Template( |
| + ' public static final String ${NAME} = "${VALUE}";') |
| + constant_entries_string = [] |
|
agrieve
2015/10/30 00:55:13
nit: don't call this _string since it holds a list
dvh
2015/10/30 20:56:20
Done.
|
| + for constant_name, constant_value in constant_definitions.iteritems(): |
| + values = { |
| + 'NAME': constant_name, |
| + 'VALUE': constant_value, |
| + } |
| + constant_entries_string.append(constant_template.substitute(values)) |
| + constant_entries_string = '\n'.join(constant_entries_string) |
| + |
| + 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): |
|
agrieve
2015/10/30 00:55:13
nit: make private
dvh
2015/10/30 20:56:20
Done.
|
| + with open(output_path + os.path.sep + 'GoogleAPIKeys.java', 'w') as out_file: |
|
agrieve
2015/10/30 00:55:13
use os.path.join() rather than os.path.sep
dvh
2015/10/30 20:56:20
Done.
|
| + out_file.write(GenerateOutput(constant_definition)) |
| + |
| +def DoMain(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(argv[0], values) |
|
agrieve
2015/10/30 00:55:13
pass this is as a --flag and use argparse so that
dvh
2015/10/30 20:56:20
Done.
|
| + |
| +if __name__ == '__main__': |
| + DoMain(sys.argv[1:]) |
| + |