OLD | NEW |
---|---|
(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 | |
14 sys.path.append( | |
15 os.path.abspath(os.path.join(sys.path[0], '../../../google_apis'))) | |
16 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.
| |
17 GetClientSecret) | |
18 | |
19 | |
20 def GetScriptName(): | |
21 script_components = os.path.abspath(sys.argv[0]).split(os.path.sep) | |
22 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.
| |
23 return os.sep.join(script_components[build_index:]) | |
24 | |
agrieve
2015/11/03 16:22:42
2 blank lines
dvh
2015/11/03 20:03:54
Done.
| |
25 def GenerateOutput(constant_definitions): | |
26 template = string.Template(""" | |
27 // Copyright 2015 The Chromium Authors. All rights reserved. | |
28 // Use of this source code is governed by a BSD-style license that can be | |
29 // found in the LICENSE file. | |
30 | |
31 // This file is autogenerated by | |
32 // ${SCRIPT_NAME} | |
33 // From | |
34 // ${SOURCE_PATH} | |
35 | |
36 package ${PACKAGE}; | |
37 | |
38 public class ${CLASS_NAME} { | |
39 ${CONSTANT_ENTRIES} | |
40 } | |
41 """) | |
42 | |
43 | |
44 constant_template = string.Template( | |
45 ' public static final String ${NAME} = "${VALUE}";') | |
46 constant_entries_list = [] | |
47 for constant_name, constant_value in constant_definitions.iteritems(): | |
48 values = { | |
49 'NAME': constant_name, | |
50 'VALUE': constant_value, | |
51 } | |
52 constant_entries_list.append(constant_template.substitute(values)) | |
53 constant_entries_string = '\n'.join(constant_entries_list) | |
54 | |
55 values = { | |
56 'CLASS_NAME': 'GoogleAPIKeys', | |
57 'CONSTANT_ENTRIES': constant_entries_string, | |
58 'PACKAGE': 'org.chromium.chrome', | |
59 'SCRIPT_NAME': GetScriptName(), | |
60 'SOURCE_PATH': 'google_api_keys/google_api_keys.h', | |
61 } | |
62 return template.substitute(values) | |
63 | |
64 def _DoWriteOutput(output_path, constant_definition): | |
65 folder = os.path.dirname(output_path) | |
66 if not os.path.exists(folder): | |
67 os.makedirs(folder) | |
68 with open(output_path, 'w') as out_file: | |
69 out_file.write(GenerateOutput(constant_definition)) | |
70 | |
71 def _DoMain(argv): | |
72 parser = argparse.ArgumentParser() | |
73 parser.add_argument("--out", help="Output file.", required=True) | |
74 options = parser.parse_args(argv) | |
75 | |
76 values = {} | |
77 values['GOOGLE_API_KEY'] = GetAPIKey() | |
78 values['GOOGLE_API_KEY_REMOTING'] = GetAPIKeyRemoting() | |
79 values['GOOGLE_CLIENT_ID_MAIN'] = GetClientID('MAIN') | |
80 values['GOOGLE_CLIENT_SECRET_MAIN'] = GetClientSecret('MAIN') | |
81 values['GOOGLE_CLIENT_ID_CLOUD_PRINT'] = GetClientID('CLOUD_PRINT') | |
82 values['GOOGLE_CLIENT_SECRET_CLOUD_PRINT'] = GetClientSecret('CLOUD_PRINT') | |
83 values['GOOGLE_CLIENT_ID_REMOTING'] = GetClientID('REMOTING') | |
84 values['GOOGLE_CLIENT_SECRET_REMOTING'] = GetClientSecret('REMOTING') | |
85 values['GOOGLE_CLIENT_ID_REMOTING_HOST'] = GetClientID('REMOTING_HOST') | |
86 values['GOOGLE_CLIENT_SECRET_REMOTING_HOST'] = GetClientSecret( | |
87 'REMOTING_HOST') | |
88 values['GOOGLE_CLIENT_ID_REMOTING_IDENTITY_API'] = GetClientID( | |
89 'REMOTING_IDENTITY_API') | |
90 _DoWriteOutput(options.out, values) | |
91 | |
92 if __name__ == '__main__': | |
93 _DoMain(sys.argv[1:]) | |
94 | |
OLD | NEW |