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..fc6f5623e4e31e38032691ac86fb24ad6b42bd12 |
--- /dev/null |
+++ b/build/android/gyp/java_google_api_keys.py |
@@ -0,0 +1,115 @@ |
+#!/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 |
+import zipfile |
+ |
+sys.path.append( |
+ os.path.abspath(os.path.join(sys.path[0], '../../../google_apis'))) |
+import google_api_keys |
+ |
+sys.path.append(os.path.abspath(os.path.join( |
+ os.path.dirname(__file__), os.pardir))) |
+from pylib import constants |
+ |
+ |
+PACKAGE = 'org.chromium.chrome' |
+CLASSNAME = 'GoogleAPIKeys' |
+HERMETIC_TIMESTAMP = (2001, 1, 1, 0, 0, 0) |
+HERMETIC_FILE_ATTR = (0644 << 16L) |
+ |
+ |
+def GetScriptName(): |
+ return os.path.relpath(__file__, constants.DIR_SOURCE_ROOT) |
+ |
+ |
+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': CLASSNAME, |
+ 'CONSTANT_ENTRIES': constant_entries_string, |
+ 'PACKAGE': PACKAGE, |
+ '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 len(folder) > 0 and not os.path.exists(folder): |
agrieve
2015/11/03 20:27:34
nit: len(folder) > 0 -> folder
dvh
2015/11/04 00:08:42
Done.
|
+ os.makedirs(folder) |
+ with zipfile.ZipFile(output_path, 'w') as srcjar: |
+ arcname = '%s/%s' % (PACKAGE.replace('.', '/'), CLASSNAME + '.java') |
+ zipinfo = zipfile.ZipInfo(filename=output_path, |
+ date_time=HERMETIC_TIMESTAMP) |
+ zipinfo.external_attr = HERMETIC_FILE_ATTR |
+ srcjar.writestr(arcname, GenerateOutput(constant_definition)) |
agrieve
2015/11/03 20:27:34
arcname -> zipinfo
dvh
2015/11/04 00:08:42
Done.
|
+ |
+ |
+def _DoMain(argv): |
+ parser = argparse.ArgumentParser() |
+ parser.add_argument("--srcjar", help="Path for srcjar output.", required=True) |
+ options = parser.parse_args(argv) |
+ |
+ values = {} |
+ values['GOOGLE_API_KEY'] = google_api_keys.GetAPIKey() |
+ values['GOOGLE_API_KEY_REMOTING'] = google_api_keys.GetAPIKeyRemoting() |
+ values['GOOGLE_CLIENT_ID_MAIN'] = google_api_keys.GetClientID('MAIN') |
+ values['GOOGLE_CLIENT_SECRET_MAIN'] = google_api_keys.GetClientSecret('MAIN') |
+ values['GOOGLE_CLIENT_ID_CLOUD_PRINT'] = google_api_keys.GetClientID( |
+ 'CLOUD_PRINT') |
+ values['GOOGLE_CLIENT_SECRET_CLOUD_PRINT'] = google_api_keys.GetClientSecret( |
+ 'CLOUD_PRINT') |
+ values['GOOGLE_CLIENT_ID_REMOTING'] = google_api_keys.GetClientID('REMOTING') |
+ values['GOOGLE_CLIENT_SECRET_REMOTING'] = google_api_keys.GetClientSecret( |
+ 'REMOTING') |
+ values['GOOGLE_CLIENT_ID_REMOTING_HOST'] = google_api_keys.GetClientID( |
+ 'REMOTING_HOST') |
+ values['GOOGLE_CLIENT_SECRET_REMOTING_HOST'] = (google_api_keys. |
+ GetClientSecret('REMOTING_HOST')) |
+ values['GOOGLE_CLIENT_ID_REMOTING_IDENTITY_API'] = (google_api_keys. |
+ GetClientID('REMOTING_IDENTITY_API')) |
+ |
+ if options.srcjar is not None: |
agrieve
2015/11/03 20:27:34
nit: if options.srcjar is not None: -> if options.
dvh
2015/11/04 00:08:42
Done.
|
+ _DoWriteOutput(options.srcjar, values) |
+ |
+ |
+if __name__ == '__main__': |
+ _DoMain(sys.argv[1:]) |
+ |