OLD | NEW |
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 Loading... |
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 | |
79 def buildWebApp(buildtype, version, destination, zip_path, | 78 def buildWebApp(buildtype, version, destination, zip_path, |
80 manifest_template, webapp_type, app_id, app_name, | 79 manifest_template, webapp_type, app_id, app_name, |
81 app_description, files, locales, jinja_paths, | 80 app_description, app_capabilities, files, locales, jinja_paths, |
82 service_environment): | 81 service_environment): |
83 """Does the main work of building the webapp directory and zipfile. | 82 """Does the main work of building the webapp directory and zipfile. |
84 | 83 |
85 Args: | 84 Args: |
86 buildtype: the type of build ("Official", "Release" or "Dev"). | 85 buildtype: the type of build ("Official", "Release" or "Dev"). |
87 destination: A string with path to directory where the webapp will be | 86 destination: A string with path to directory where the webapp will be |
88 written. | 87 written. |
89 zipfile: A string with path to the zipfile to create containing the | 88 zipfile: A string with path to the zipfile to create containing the |
90 contents of |destination|. | 89 contents of |destination|. |
91 manifest_template: jinja2 template file for manifest. | 90 manifest_template: jinja2 template file for manifest. |
92 webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting"). | 91 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 | 92 app_id: A string with the Remoting Application Id (only used for app |
94 remoting webapps). If supplied, it defaults to using the | 93 remoting webapps). If supplied, it defaults to using the |
95 test API server. | 94 test API server. |
96 app_name: A string with the name of the application. | 95 app_name: A string with the name of the application. |
97 app_description: A string with the description of the application. | 96 app_description: A string with the description of the application. |
| 97 app_capabilities: A set of strings naming the capabilities that should be |
| 98 enabled for this application. |
98 files: An array of strings listing the paths for resources to include | 99 files: An array of strings listing the paths for resources to include |
99 in this webapp. | 100 in this webapp. |
100 locales: An array of strings listing locales, which are copied, along | 101 locales: An array of strings listing locales, which are copied, along |
101 with their directory structure from the _locales directory down. | 102 with their directory structure from the _locales directory down. |
102 jinja_paths: An array of paths to search for {%include} directives in | 103 jinja_paths: An array of paths to search for {%include} directives in |
103 addition to the directory containing the manifest template. | 104 addition to the directory containing the manifest template. |
104 service_environment: Used to point the webApp to one of the | 105 service_environment: Used to point the webApp to one of the |
105 dev/test/staging/prod environments | 106 dev/test/staging/prod environments |
106 """ | 107 """ |
107 # Ensure a fresh directory. | 108 # Ensure a fresh directory. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 310 |
310 # Set the correct API keys. | 311 # Set the correct API keys. |
311 # For overriding the client ID/secret via env vars, see google_api_keys.py. | 312 # For overriding the client ID/secret via env vars, see google_api_keys.py. |
312 apiClientId = google_api_keys.GetClientID('REMOTING') | 313 apiClientId = google_api_keys.GetClientID('REMOTING') |
313 apiClientSecret = google_api_keys.GetClientSecret('REMOTING') | 314 apiClientSecret = google_api_keys.GetClientSecret('REMOTING') |
314 apiClientIdV2 = google_api_keys.GetClientID('REMOTING_IDENTITY_API') | 315 apiClientIdV2 = google_api_keys.GetClientID('REMOTING_IDENTITY_API') |
315 | 316 |
316 replaceString(destination, 'API_CLIENT_ID', apiClientId) | 317 replaceString(destination, 'API_CLIENT_ID', apiClientId) |
317 replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret) | 318 replaceString(destination, 'API_CLIENT_SECRET', apiClientSecret) |
318 | 319 |
| 320 # Write the application capabilities. |
| 321 appCapabilities = ','.join( |
| 322 ['remoting.ClientSession.Capability.' + x for x in app_capabilities]) |
| 323 findAndReplace(os.path.join(destination, 'app_capabilities.js'), |
| 324 "'APPLICATION_CAPABILITIES'", appCapabilities) |
| 325 |
319 # Use a consistent extension id for dev builds. | 326 # Use a consistent extension id for dev builds. |
320 # AppRemoting builds always use the dev app id - the correct app id gets | 327 # AppRemoting builds always use the dev app id - the correct app id gets |
321 # written into the manifest later. | 328 # written into the manifest later. |
322 if buildtype != 'Official' or webapp_type == 'app_remoting': | 329 if buildtype != 'Official' or webapp_type == 'app_remoting': |
323 manifestKey = '"key": "remotingdevbuild",' | 330 manifestKey = '"key": "remotingdevbuild",' |
324 else: | 331 else: |
325 manifestKey = '' | 332 manifestKey = '' |
326 | 333 |
327 # Generate manifest. | 334 # Generate manifest. |
328 if manifest_template: | 335 if manifest_template: |
329 context = { | 336 context = { |
330 'webapp_type': webapp_type, | 337 'webapp_type': webapp_type, |
331 'FULL_APP_VERSION': version, | 338 'FULL_APP_VERSION': version, |
332 'MANIFEST_KEY_FOR_UNOFFICIAL_BUILD': manifestKey, | 339 'MANIFEST_KEY_FOR_UNOFFICIAL_BUILD': manifestKey, |
333 'OAUTH2_REDIRECT_URL': oauth2RedirectUrlJson, | 340 'OAUTH2_REDIRECT_URL': oauth2RedirectUrlJson, |
334 'TALK_GADGET_HOST': talkGadgetHostJson, | 341 'TALK_GADGET_HOST': talkGadgetHostJson, |
335 'THIRD_PARTY_AUTH_REDIRECT_URL': thirdPartyAuthUrlJson, | 342 'THIRD_PARTY_AUTH_REDIRECT_URL': thirdPartyAuthUrlJson, |
336 'REMOTING_IDENTITY_API_CLIENT_ID': apiClientIdV2, | 343 'REMOTING_IDENTITY_API_CLIENT_ID': apiClientIdV2, |
337 'OAUTH2_BASE_URL': oauth2BaseUrl, | 344 'OAUTH2_BASE_URL': oauth2BaseUrl, |
338 'OAUTH2_API_BASE_URL': oauth2ApiBaseUrl, | 345 'OAUTH2_API_BASE_URL': oauth2ApiBaseUrl, |
339 'DIRECTORY_API_BASE_URL': directoryApiBaseUrl, | 346 'DIRECTORY_API_BASE_URL': directoryApiBaseUrl, |
340 'APP_REMOTING_API_BASE_URL': appRemotingApiBaseUrl, | 347 'APP_REMOTING_API_BASE_URL': appRemotingApiBaseUrl, |
341 'OAUTH2_ACCOUNTS_HOST': oauth2AccountsHost, | 348 'OAUTH2_ACCOUNTS_HOST': oauth2AccountsHost, |
342 'GOOGLE_API_HOSTS': googleApiHosts, | 349 'GOOGLE_API_HOSTS': googleApiHosts, |
343 'APP_NAME': app_name, | 350 'APP_NAME': app_name, |
344 'APP_DESCRIPTION': app_description, | 351 'APP_DESCRIPTION': app_description, |
| 352 'OAUTH_GDRIVE_SCOPE': '', |
345 } | 353 } |
| 354 if 'GOOGLE_DRIVE' in app_capabilities: |
| 355 context['OAUTH_GDRIVE_SCOPE'] = ('https://docs.google.com/feeds/ ' |
| 356 'https://www.googleapis.com/auth/drive') |
346 processJinjaTemplate(manifest_template, | 357 processJinjaTemplate(manifest_template, |
347 jinja_paths, | 358 jinja_paths, |
348 os.path.join(destination, 'manifest.json'), | 359 os.path.join(destination, 'manifest.json'), |
349 context) | 360 context) |
350 | 361 |
351 # Make the zipfile. | 362 # Make the zipfile. |
352 createZip(zip_path, destination) | 363 createZip(zip_path, destination) |
353 | 364 |
354 return 0 | 365 return 0 |
355 | 366 |
356 | 367 |
357 def main(): | 368 def main(): |
358 if len(sys.argv) < 6: | 369 if len(sys.argv) < 6: |
359 print ('Usage: build-webapp.py ' | 370 print ('Usage: build-webapp.py ' |
360 '<build-type> <version> <dst> <zip-path> <manifest_template> ' | 371 '<build-type> <version> <dst> <zip-path> <manifest_template> ' |
361 '<webapp_type> <other files...> ' | 372 '<webapp_type> <other files...> ' |
362 '--app_name <name> ' | 373 '--app_name <name> ' |
363 '--app_description <description> ' | 374 '--app_description <description> ' |
| 375 '--app_capabilities <capabilities...> ' |
364 '[--appid <appid>] ' | 376 '[--appid <appid>] ' |
365 '[--locales <locales...>] ' | 377 '[--locales <locales...>] ' |
366 '[--jinja_paths <paths...>] ' | 378 '[--jinja_paths <paths...>] ' |
367 '[--service_environment <service_environment>]') | 379 '[--service_environment <service_environment>]') |
368 return 1 | 380 return 1 |
369 | 381 |
370 arg_type = '' | 382 arg_type = '' |
371 files = [] | 383 files = [] |
372 locales = [] | 384 locales = [] |
373 jinja_paths = [] | 385 jinja_paths = [] |
374 app_id = None | 386 app_id = None |
375 app_name = None | 387 app_name = None |
376 app_description = None | 388 app_description = None |
| 389 app_capabilities = set([]) |
377 service_environment = '' | 390 service_environment = '' |
378 | 391 |
379 for arg in sys.argv[7:]: | 392 for arg in sys.argv[7:]: |
380 if arg in ['--locales', | 393 if arg in ['--locales', |
381 '--jinja_paths', | 394 '--jinja_paths', |
382 '--appid', | 395 '--appid', |
383 '--app_name', | 396 '--app_name', |
384 '--app_description', | 397 '--app_description', |
| 398 '--app_capabilities', |
385 '--service_environment']: | 399 '--service_environment']: |
386 arg_type = arg | 400 arg_type = arg |
387 elif arg_type == '--locales': | 401 elif arg_type == '--locales': |
388 locales.append(arg) | 402 locales.append(arg) |
389 elif arg_type == '--jinja_paths': | 403 elif arg_type == '--jinja_paths': |
390 jinja_paths.append(arg) | 404 jinja_paths.append(arg) |
391 elif arg_type == '--appid': | 405 elif arg_type == '--appid': |
392 app_id = arg | 406 app_id = arg |
393 arg_type = '' | 407 arg_type = '' |
394 elif arg_type == '--app_name': | 408 elif arg_type == '--app_name': |
395 app_name = arg | 409 app_name = arg |
396 arg_type = '' | 410 arg_type = '' |
397 elif arg_type == '--app_description': | 411 elif arg_type == '--app_description': |
398 app_description = arg | 412 app_description = arg |
399 arg_type = '' | 413 arg_type = '' |
| 414 elif arg_type == '--app_capabilities': |
| 415 app_capabilities.add(arg) |
400 elif arg_type == '--service_environment': | 416 elif arg_type == '--service_environment': |
401 service_environment = arg | 417 service_environment = arg |
402 arg_type = '' | 418 arg_type = '' |
403 else: | 419 else: |
404 files.append(arg) | 420 files.append(arg) |
405 | 421 |
406 return buildWebApp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], | 422 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, | 423 sys.argv[5], sys.argv[6], app_id, app_name, |
408 app_description, files, locales, jinja_paths, | 424 app_description, app_capabilities, files, locales, |
409 service_environment) | 425 jinja_paths, service_environment) |
410 | 426 |
411 | 427 |
412 if __name__ == '__main__': | 428 if __name__ == '__main__': |
413 sys.exit(main()) | 429 sys.exit(main()) |
OLD | NEW |