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

Side by Side Diff: remoting/webapp/build-webapp.py

Issue 895523004: [Chromoting] Add ability to enable/disable GDrive support per-app in gyp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Creates a directory with with the unpacked contents of the remoting webapp. 6 """Creates a directory with with the unpacked contents of the remoting webapp.
7 7
8 The directory will contain a copy-of or a link-to to all remoting webapp 8 The directory will contain a copy-of or a link-to to all remoting webapp
9 resources. This includes HTML/JS and any plugin binaries. The script also 9 resources. This includes HTML/JS and any plugin binaries. The script also
10 massages resulting files appropriately with host plugin data. Finally, 10 massages resulting files appropriately with host plugin data. Finally,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 '../../../third_party/jinja2')) 68 '../../../third_party/jinja2'))
69 sys.path.append(os.path.split(jinja2_path)[0]) 69 sys.path.append(os.path.split(jinja2_path)[0])
70 import jinja2 70 import jinja2
71 (template_path, template_name) = os.path.split(input_file) 71 (template_path, template_name) = os.path.split(input_file)
72 include_paths = [template_path] + include_paths 72 include_paths = [template_path] + include_paths
73 env = jinja2.Environment(loader=jinja2.FileSystemLoader(include_paths)) 73 env = jinja2.Environment(loader=jinja2.FileSystemLoader(include_paths))
74 template = env.get_template(template_name) 74 template = env.get_template(template_name)
75 rendered = template.render(context) 75 rendered = template.render(context)
76 io.open(output_file, 'w', encoding='utf-8').write(rendered) 76 io.open(output_file, 'w', encoding='utf-8').write(rendered)
77 77
78 78
Jamie 2015/02/03 18:06:24 I think this blank line should stay, because it se
79 def buildWebApp(buildtype, version, destination, zip_path, 79 def buildWebApp(buildtype, version, destination, zip_path,
80 manifest_template, webapp_type, app_id, app_name, 80 manifest_template, webapp_type, app_id, app_name,
81 app_description, files, locales, jinja_paths, 81 app_description, app_features, files, locales, jinja_paths,
82 service_environment): 82 service_environment):
83 """Does the main work of building the webapp directory and zipfile. 83 """Does the main work of building the webapp directory and zipfile.
84 84
85 Args: 85 Args:
86 buildtype: the type of build ("Official", "Release" or "Dev"). 86 buildtype: the type of build ("Official", "Release" or "Dev").
87 destination: A string with path to directory where the webapp will be 87 destination: A string with path to directory where the webapp will be
88 written. 88 written.
89 zipfile: A string with path to the zipfile to create containing the 89 zipfile: A string with path to the zipfile to create containing the
90 contents of |destination|. 90 contents of |destination|.
91 manifest_template: jinja2 template file for manifest. 91 manifest_template: jinja2 template file for manifest.
92 webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting"). 92 webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting").
93 app_id: A string with the Remoting Application Id (only used for app 93 app_id: A string with the Remoting Application Id (only used for app
94 remoting webapps). If supplied, it defaults to using the 94 remoting webapps). If supplied, it defaults to using the
95 test API server. 95 test API server.
96 app_name: A string with the name of the application. 96 app_name: A string with the name of the application.
97 app_description: A string with the description of the application. 97 app_description: A string with the description of the application.
98 app_features: A set of strings naming the features that should be enabled
99 for this application.
98 files: An array of strings listing the paths for resources to include 100 files: An array of strings listing the paths for resources to include
99 in this webapp. 101 in this webapp.
100 locales: An array of strings listing locales, which are copied, along 102 locales: An array of strings listing locales, which are copied, along
101 with their directory structure from the _locales directory down. 103 with their directory structure from the _locales directory down.
102 jinja_paths: An array of paths to search for {%include} directives in 104 jinja_paths: An array of paths to search for {%include} directives in
103 addition to the directory containing the manifest template. 105 addition to the directory containing the manifest template.
104 service_environment: Used to point the webApp to one of the 106 service_environment: Used to point the webApp to one of the
105 dev/test/staging/prod environments 107 dev/test/staging/prod environments
106 """ 108 """
107 # Ensure a fresh directory. 109 # Ensure a fresh directory.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 # If an Application ID was set (either from service_environment variable or 213 # If an Application ID was set (either from service_environment variable or
212 # from a command line argument), hardcode it, otherwise get it at runtime. 214 # from a command line argument), hardcode it, otherwise get it at runtime.
213 effectiveAppId = appRemotingApplicationId or app_id 215 effectiveAppId = appRemotingApplicationId or app_id
214 if effectiveAppId: 216 if effectiveAppId:
215 appRemotingApplicationId = "'" + effectiveAppId + "'" 217 appRemotingApplicationId = "'" + effectiveAppId + "'"
216 else: 218 else:
217 appRemotingApplicationId = "chrome.i18n.getMessage('@@extension_id')" 219 appRemotingApplicationId = "chrome.i18n.getMessage('@@extension_id')"
218 findAndReplace(os.path.join(destination, 'plugin_settings.js'), 220 findAndReplace(os.path.join(destination, 'plugin_settings.js'),
219 "'APP_REMOTING_APPLICATION_ID'", appRemotingApplicationId) 221 "'APP_REMOTING_APPLICATION_ID'", appRemotingApplicationId)
220 222
223
Jamie 2015/02/02 22:57:47 No need for an extra blank line here (IIRC, that c
garykac 2015/02/03 01:50:21 I fixed this locally but forgot to upload. grr.
221 oauth2BaseUrl = oauth2AccountsHost + '/o/oauth2' 224 oauth2BaseUrl = oauth2AccountsHost + '/o/oauth2'
222 oauth2ApiBaseUrl = oauth2ApiHost + '/oauth2' 225 oauth2ApiBaseUrl = oauth2ApiHost + '/oauth2'
223 directoryApiBaseUrl = directoryApiHost + '/chromoting/v1' 226 directoryApiBaseUrl = directoryApiHost + '/chromoting/v1'
224 227
225 if webapp_type == 'app_remoting': 228 if webapp_type == 'app_remoting':
226 # Set the apiary endpoint and then set the endpoint version 229 # Set the apiary endpoint and then set the endpoint version
227 if not appRemotingApiHost: 230 if not appRemotingApiHost:
228 if service_environment == 'prod': 231 if service_environment == 'prod':
229 appRemotingApiHost = 'https://www.googleapis.com' 232 appRemotingApiHost = 'https://www.googleapis.com'
230 else: 233 else:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 312
310 # Set the correct API keys. 313 # Set the correct API keys.
311 # For overriding the client ID/secret via env vars, see google_api_keys.py. 314 # For overriding the client ID/secret via env vars, see google_api_keys.py.
312 apiClientId = google_api_keys.GetClientID('REMOTING') 315 apiClientId = google_api_keys.GetClientID('REMOTING')
313 apiClientSecret = google_api_keys.GetClientSecret('REMOTING') 316 apiClientSecret = google_api_keys.GetClientSecret('REMOTING')
314 apiClientIdV2 = google_api_keys.GetClientID('REMOTING_IDENTITY_API') 317 apiClientIdV2 = google_api_keys.GetClientID('REMOTING_IDENTITY_API')
315 318
316 replaceString(destination, 'API_CLIENT_ID', apiClientId) 319 replaceString(destination, 'API_CLIENT_ID', apiClientId)
317 replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret) 320 replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret)
318 321
322 # Write the application features.
323 appFeatures = ''.join(["'" + x + "'" for x in app_features])
324 findAndReplace(os.path.join(destination, 'app_features.js'),
325 "'APPLICATION_FEATURES'", appFeatures)
326
319 # Use a consistent extension id for dev builds. 327 # Use a consistent extension id for dev builds.
320 # AppRemoting builds always use the dev app id - the correct app id gets 328 # AppRemoting builds always use the dev app id - the correct app id gets
321 # written into the manifest later. 329 # written into the manifest later.
322 if buildtype != 'Official' or webapp_type == 'app_remoting': 330 if buildtype != 'Official' or webapp_type == 'app_remoting':
323 manifestKey = '"key": "remotingdevbuild",' 331 manifestKey = '"key": "remotingdevbuild",'
324 else: 332 else:
325 manifestKey = '' 333 manifestKey = ''
326 334
327 # Generate manifest. 335 # Generate manifest.
328 if manifest_template: 336 if manifest_template:
329 context = { 337 context = {
330 'webapp_type': webapp_type, 338 'webapp_type': webapp_type,
331 'FULL_APP_VERSION': version, 339 'FULL_APP_VERSION': version,
332 'MANIFEST_KEY_FOR_UNOFFICIAL_BUILD': manifestKey, 340 'MANIFEST_KEY_FOR_UNOFFICIAL_BUILD': manifestKey,
333 'OAUTH2_REDIRECT_URL': oauth2RedirectUrlJson, 341 'OAUTH2_REDIRECT_URL': oauth2RedirectUrlJson,
334 'TALK_GADGET_HOST': talkGadgetHostJson, 342 'TALK_GADGET_HOST': talkGadgetHostJson,
335 'THIRD_PARTY_AUTH_REDIRECT_URL': thirdPartyAuthUrlJson, 343 'THIRD_PARTY_AUTH_REDIRECT_URL': thirdPartyAuthUrlJson,
336 'REMOTING_IDENTITY_API_CLIENT_ID': apiClientIdV2, 344 'REMOTING_IDENTITY_API_CLIENT_ID': apiClientIdV2,
337 'OAUTH2_BASE_URL': oauth2BaseUrl, 345 'OAUTH2_BASE_URL': oauth2BaseUrl,
338 'OAUTH2_API_BASE_URL': oauth2ApiBaseUrl, 346 'OAUTH2_API_BASE_URL': oauth2ApiBaseUrl,
339 'DIRECTORY_API_BASE_URL': directoryApiBaseUrl, 347 'DIRECTORY_API_BASE_URL': directoryApiBaseUrl,
340 'APP_REMOTING_API_BASE_URL': appRemotingApiBaseUrl, 348 'APP_REMOTING_API_BASE_URL': appRemotingApiBaseUrl,
341 'OAUTH2_ACCOUNTS_HOST': oauth2AccountsHost, 349 'OAUTH2_ACCOUNTS_HOST': oauth2AccountsHost,
342 'GOOGLE_API_HOSTS': googleApiHosts, 350 'GOOGLE_API_HOSTS': googleApiHosts,
343 'APP_NAME': app_name, 351 'APP_NAME': app_name,
344 'APP_DESCRIPTION': app_description, 352 'APP_DESCRIPTION': app_description,
353 'OAUTH_GDRIVE_SCOPE': '',
345 } 354 }
355 if 'gdrive' in app_features:
356 context['OAUTH_GDRIVE_SCOPE'] = ('https://docs.google.com/feeds/ '
357 'https://www.googleapis.com/auth/drive')
346 processJinjaTemplate(manifest_template, 358 processJinjaTemplate(manifest_template,
347 jinja_paths, 359 jinja_paths,
348 os.path.join(destination, 'manifest.json'), 360 os.path.join(destination, 'manifest.json'),
349 context) 361 context)
350 362
351 # Make the zipfile. 363 # Make the zipfile.
352 createZip(zip_path, destination) 364 createZip(zip_path, destination)
353 365
354 return 0 366 return 0
355 367
356 368
357 def main(): 369 def main():
370 valid_app_features = ['cast', 'gdrive']
Jamie 2015/02/02 22:57:47 If you use an enumerated type, you can get rid of
garykac 2015/02/03 01:50:21 Done.
371
358 if len(sys.argv) < 6: 372 if len(sys.argv) < 6:
359 print ('Usage: build-webapp.py ' 373 print ('Usage: build-webapp.py '
360 '<build-type> <version> <dst> <zip-path> <manifest_template> ' 374 '<build-type> <version> <dst> <zip-path> <manifest_template> '
361 '<webapp_type> <other files...> ' 375 '<webapp_type> <other files...> '
362 '--app_name <name> ' 376 '--app_name <name> '
363 '--app_description <description> ' 377 '--app_description <description> '
378 '--app_features <features...> '
364 '[--appid <appid>] ' 379 '[--appid <appid>] '
365 '[--locales <locales...>] ' 380 '[--locales <locales...>] '
366 '[--jinja_paths <paths...>] ' 381 '[--jinja_paths <paths...>] '
367 '[--service_environment <service_environment>]') 382 '[--service_environment <service_environment>]')
383 print 'Where <features> are', valid_app_features
368 return 1 384 return 1
369 385
370 arg_type = '' 386 arg_type = ''
371 files = [] 387 files = []
372 locales = [] 388 locales = []
373 jinja_paths = [] 389 jinja_paths = []
374 app_id = None 390 app_id = None
375 app_name = None 391 app_name = None
376 app_description = None 392 app_description = None
393 app_features = set([])
377 service_environment = '' 394 service_environment = ''
378 395
379 for arg in sys.argv[7:]: 396 for arg in sys.argv[7:]:
380 if arg in ['--locales', 397 if arg in ['--locales',
381 '--jinja_paths', 398 '--jinja_paths',
382 '--appid', 399 '--appid',
383 '--app_name', 400 '--app_name',
384 '--app_description', 401 '--app_description',
402 '--app_features',
385 '--service_environment']: 403 '--service_environment']:
386 arg_type = arg 404 arg_type = arg
387 elif arg_type == '--locales': 405 elif arg_type == '--locales':
388 locales.append(arg) 406 locales.append(arg)
389 elif arg_type == '--jinja_paths': 407 elif arg_type == '--jinja_paths':
390 jinja_paths.append(arg) 408 jinja_paths.append(arg)
391 elif arg_type == '--appid': 409 elif arg_type == '--appid':
392 app_id = arg 410 app_id = arg
393 arg_type = '' 411 arg_type = ''
394 elif arg_type == '--app_name': 412 elif arg_type == '--app_name':
395 app_name = arg 413 app_name = arg
396 arg_type = '' 414 arg_type = ''
397 elif arg_type == '--app_description': 415 elif arg_type == '--app_description':
398 app_description = arg 416 app_description = arg
399 arg_type = '' 417 arg_type = ''
418 elif arg_type == '--app_features':
419 if arg in valid_app_features:
420 app_features.add(arg)
421 else:
422 raise Exception('Invalid app_feature: ' + arg)
400 elif arg_type == '--service_environment': 423 elif arg_type == '--service_environment':
401 service_environment = arg 424 service_environment = arg
402 arg_type = '' 425 arg_type = ''
403 else: 426 else:
404 files.append(arg) 427 files.append(arg)
405 428
406 return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], 429 return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4],
407 sys.argv[5], sys.argv[6], app_id, app_name, 430 sys.argv[5], sys.argv[6], app_id, app_name,
408 app_description, files, locales, jinja_paths, 431 app_description, app_features, files, locales,
409 service_environment) 432 jinja_paths, service_environment)
410 433
411 434
412 if __name__ == '__main__': 435 if __name__ == '__main__':
413 sys.exit(main()) 436 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698