Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: build/android/gyp/java_google_api_keys.py

Issue 1411913005: Make Google API keys available for the Java codebase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 # Generates a Java file with API keys.
8
9 import argparse
10 import os
11 import string
12 import sys
13 import zipfile
14
15 sys.path.append(
16 os.path.abspath(os.path.join(sys.path[0], '../../../google_apis')))
17 import google_api_keys
18
19 sys.path.append(os.path.abspath(os.path.join(
20 os.path.dirname(__file__), os.pardir)))
21 from pylib import constants
22
23
24 PACKAGE = 'org.chromium.chrome'
25 CLASSNAME = 'GoogleAPIKeys'
26 HERMETIC_TIMESTAMP = (2001, 1, 1, 0, 0, 0)
27 HERMETIC_FILE_ATTR = (0644 << 16L)
28
29
30 def GetScriptName():
31 return os.path.relpath(__file__, constants.DIR_SOURCE_ROOT)
32
33
34 def GenerateOutput(constant_definitions):
35 template = string.Template("""
36 // Copyright 2015 The Chromium Authors. All rights reserved.
37 // Use of this source code is governed by a BSD-style license that can be
38 // found in the LICENSE file.
39
40 // This file is autogenerated by
41 // ${SCRIPT_NAME}
42 // From
43 // ${SOURCE_PATH}
44
45 package ${PACKAGE};
46
47 public class ${CLASS_NAME} {
48 ${CONSTANT_ENTRIES}
49 }
50 """)
51
52 constant_template = string.Template(
53 ' public static final String ${NAME} = "${VALUE}";')
54 constant_entries_list = []
55 for constant_name, constant_value in constant_definitions.iteritems():
56 values = {
57 'NAME': constant_name,
58 'VALUE': constant_value,
59 }
60 constant_entries_list.append(constant_template.substitute(values))
61 constant_entries_string = '\n'.join(constant_entries_list)
62
63 values = {
64 'CLASS_NAME': CLASSNAME,
65 'CONSTANT_ENTRIES': constant_entries_string,
66 'PACKAGE': PACKAGE,
67 'SCRIPT_NAME': GetScriptName(),
68 'SOURCE_PATH': 'google_api_keys/google_api_keys.h',
69 }
70 return template.substitute(values)
71
72
73 def _DoWriteOutput(output_path, constant_definition):
74 folder = os.path.dirname(output_path)
75 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.
76 os.makedirs(folder)
77 with zipfile.ZipFile(output_path, 'w') as srcjar:
78 arcname = '%s/%s' % (PACKAGE.replace('.', '/'), CLASSNAME + '.java')
79 zipinfo = zipfile.ZipInfo(filename=output_path,
80 date_time=HERMETIC_TIMESTAMP)
81 zipinfo.external_attr = HERMETIC_FILE_ATTR
82 srcjar.writestr(arcname, GenerateOutput(constant_definition))
agrieve 2015/11/03 20:27:34 arcname -> zipinfo
dvh 2015/11/04 00:08:42 Done.
83
84
85 def _DoMain(argv):
86 parser = argparse.ArgumentParser()
87 parser.add_argument("--srcjar", help="Path for srcjar output.", required=True)
88 options = parser.parse_args(argv)
89
90 values = {}
91 values['GOOGLE_API_KEY'] = google_api_keys.GetAPIKey()
92 values['GOOGLE_API_KEY_REMOTING'] = google_api_keys.GetAPIKeyRemoting()
93 values['GOOGLE_CLIENT_ID_MAIN'] = google_api_keys.GetClientID('MAIN')
94 values['GOOGLE_CLIENT_SECRET_MAIN'] = google_api_keys.GetClientSecret('MAIN')
95 values['GOOGLE_CLIENT_ID_CLOUD_PRINT'] = google_api_keys.GetClientID(
96 'CLOUD_PRINT')
97 values['GOOGLE_CLIENT_SECRET_CLOUD_PRINT'] = google_api_keys.GetClientSecret(
98 'CLOUD_PRINT')
99 values['GOOGLE_CLIENT_ID_REMOTING'] = google_api_keys.GetClientID('REMOTING')
100 values['GOOGLE_CLIENT_SECRET_REMOTING'] = google_api_keys.GetClientSecret(
101 'REMOTING')
102 values['GOOGLE_CLIENT_ID_REMOTING_HOST'] = google_api_keys.GetClientID(
103 'REMOTING_HOST')
104 values['GOOGLE_CLIENT_SECRET_REMOTING_HOST'] = (google_api_keys.
105 GetClientSecret('REMOTING_HOST'))
106 values['GOOGLE_CLIENT_ID_REMOTING_IDENTITY_API'] = (google_api_keys.
107 GetClientID('REMOTING_IDENTITY_API'))
108
109 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.
110 _DoWriteOutput(options.srcjar, values)
111
112
113 if __name__ == '__main__':
114 _DoMain(sys.argv[1:])
115
OLDNEW
« no previous file with comments | « no previous file | build/android/gyp/java_google_api_keys_tests.py » ('j') | build/android/gyp/java_google_api_keys_tests.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698