Chromium Code Reviews| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 (template_path, template_name) = os.path.split(input_file) | 102 (template_path, template_name) = os.path.split(input_file) |
| 103 include_paths = [template_path] + include_paths | 103 include_paths = [template_path] + include_paths |
| 104 env = jinja2.Environment(loader=jinja2.FileSystemLoader(include_paths)) | 104 env = jinja2.Environment(loader=jinja2.FileSystemLoader(include_paths)) |
| 105 template = env.get_template(template_name) | 105 template = env.get_template(template_name) |
| 106 rendered = template.render(context) | 106 rendered = template.render(context) |
| 107 io.open(output_file, 'w', encoding='utf-8').write(rendered) | 107 io.open(output_file, 'w', encoding='utf-8').write(rendered) |
| 108 | 108 |
| 109 def buildWebApp(buildtype, version, destination, zip_path, | 109 def buildWebApp(buildtype, version, destination, zip_path, |
| 110 manifest_template, webapp_type, appid, app_client_id, app_name, | 110 manifest_template, webapp_type, appid, app_client_id, app_name, |
| 111 app_description, app_capabilities, manifest_key, files, | 111 app_description, app_capabilities, manifest_key, files, |
| 112 locales_listfile, jinja_paths, service_environment, use_gcd): | 112 files_listfile, locales_listfile, jinja_paths, |
| 113 service_environment, use_gcd): | |
| 113 """Does the main work of building the webapp directory and zipfile. | 114 """Does the main work of building the webapp directory and zipfile. |
| 114 | 115 |
| 115 Args: | 116 Args: |
| 116 buildtype: the type of build ("Official", "Release" or "Dev"). | 117 buildtype: the type of build ("Official", "Release" or "Dev"). |
| 117 destination: A string with path to directory where the webapp will be | 118 destination: A string with path to directory where the webapp will be |
| 118 written. | 119 written. |
| 119 zipfile: A string with path to the zipfile to create containing the | 120 zipfile: A string with path to the zipfile to create containing the |
| 120 contents of |destination|. | 121 contents of |destination|. |
| 121 manifest_template: jinja2 template file for manifest. | 122 manifest_template: jinja2 template file for manifest. |
| 122 webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting"). | 123 webapp_type: webapp type ("v1", "v2", "v2_pnacl" or "app_remoting"). |
| 123 appid: A string with the Remoting Application Id (only used for app | 124 appid: A string with the Remoting Application Id (only used for app |
| 124 remoting webapps). If supplied, it defaults to using the | 125 remoting webapps). If supplied, it defaults to using the |
| 125 test API server. | 126 test API server. |
| 126 app_client_id: The OAuth2 client ID for the webapp. | 127 app_client_id: The OAuth2 client ID for the webapp. |
| 127 app_name: A string with the name of the application. | 128 app_name: A string with the name of the application. |
| 128 app_description: A string with the description of the application. | 129 app_description: A string with the description of the application. |
| 129 app_capabilities: A set of strings naming the capabilities that should be | 130 app_capabilities: A set of strings naming the capabilities that should be |
| 130 enabled for this application. | 131 enabled for this application. |
| 131 manifest_key: The manifest key for the webapp. | 132 manifest_key: The manifest key for the webapp. |
| 132 files: An array of strings listing the paths for resources to include | 133 files: An array of strings listing the paths for resources to include |
| 133 in this webapp. | 134 in this webapp. |
| 135 files_listfile: The name of a file containing a list of files, one per | |
| 136 line, identifying the resources to include in this webapp. This | |
|
Jamie
2015/04/24 23:51:49
Nit: Indentation.
garykac
2015/04/27 15:36:16
Done.
| |
| 137 is an alternate to specifying the files directly via the 'files' | |
| 138 option. The files listed in this file are appended to the files | |
| 139 passed via the 'files' option, if any. | |
| 134 locales_listfile: The name of a file containing a list of locales, one per | 140 locales_listfile: The name of a file containing a list of locales, one per |
| 135 line, which are copied, along with their directory structure, from | 141 line, which are copied, along with their directory structure, from |
| 136 the _locales directory down. | 142 the _locales directory down. |
| 137 jinja_paths: An array of paths to search for {%include} directives in | 143 jinja_paths: An array of paths to search for {%include} directives in |
| 138 addition to the directory containing the manifest template. | 144 addition to the directory containing the manifest template. |
| 139 service_environment: Used to point the webapp to one of the | 145 service_environment: Used to point the webapp to one of the |
| 140 dev/test/staging/prod/prod-testing environments | 146 dev/test/staging/prod/prod-testing environments |
| 141 use_gcd: True if GCD support should be enabled. | 147 use_gcd: True if GCD support should be enabled. |
| 142 """ | 148 """ |
| 143 | 149 |
| 144 # Load the locales files from the locales_listfile. | 150 # Load the locales files from the locales_listfile. |
| 145 if not locales_listfile: | 151 if not locales_listfile: |
| 146 raise Exception('You must specify a locales_listfile') | 152 raise Exception('You must specify a locales_listfile') |
| 147 locales = [] | 153 locales = [] |
| 148 with open(locales_listfile) as input: | 154 with open(locales_listfile) as input: |
| 149 for s in input: | 155 for s in input: |
| 150 locales.append(s.rstrip()) | 156 locales.append(s.rstrip()) |
| 151 | 157 |
| 158 # Load the files from the files_listfile. | |
| 159 if files_listfile: | |
| 160 with open(files_listfile) as input: | |
| 161 for s in input: | |
| 162 files.append(s.rstrip()) | |
| 163 | |
| 152 # Ensure a fresh directory. | 164 # Ensure a fresh directory. |
| 153 try: | 165 try: |
| 154 shutil.rmtree(destination) | 166 shutil.rmtree(destination) |
| 155 except OSError: | 167 except OSError: |
| 156 if os.path.exists(destination): | 168 if os.path.exists(destination): |
| 157 raise | 169 raise |
| 158 else: | 170 else: |
| 159 pass | 171 pass |
| 160 os.mkdir(destination, 0775) | 172 os.mkdir(destination, 0775) |
| 161 | 173 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 parser.add_argument('manifest_template') | 442 parser.add_argument('manifest_template') |
| 431 parser.add_argument('webapp_type') | 443 parser.add_argument('webapp_type') |
| 432 parser.add_argument('files', nargs='*', metavar='file', default=[]) | 444 parser.add_argument('files', nargs='*', metavar='file', default=[]) |
| 433 parser.add_argument('--app_name', metavar='NAME') | 445 parser.add_argument('--app_name', metavar='NAME') |
| 434 parser.add_argument('--app_description', metavar='TEXT') | 446 parser.add_argument('--app_description', metavar='TEXT') |
| 435 parser.add_argument('--app_capabilities', | 447 parser.add_argument('--app_capabilities', |
| 436 nargs='*', default=[], metavar='CAPABILITY') | 448 nargs='*', default=[], metavar='CAPABILITY') |
| 437 parser.add_argument('--appid') | 449 parser.add_argument('--appid') |
| 438 parser.add_argument('--app_client_id', default='') | 450 parser.add_argument('--app_client_id', default='') |
| 439 parser.add_argument('--manifest_key', default='') | 451 parser.add_argument('--manifest_key', default='') |
| 452 parser.add_argument('--files_listfile', default='', metavar='PATH') | |
| 440 parser.add_argument('--locales_listfile', default='', metavar='PATH') | 453 parser.add_argument('--locales_listfile', default='', metavar='PATH') |
| 441 parser.add_argument('--jinja_paths', nargs='*', default=[], metavar='PATH') | 454 parser.add_argument('--jinja_paths', nargs='*', default=[], metavar='PATH') |
| 442 parser.add_argument('--service_environment', default='', metavar='ENV') | 455 parser.add_argument('--service_environment', default='', metavar='ENV') |
| 443 parser.add_argument('--use_gcd', choices=['0', '1'], default='0') | 456 parser.add_argument('--use_gcd', choices=['0', '1'], default='0') |
| 444 | 457 |
| 445 args = parser.parse_args() | 458 args = parser.parse_args() |
| 446 args.use_gcd = (args.use_gcd != '0') | 459 args.use_gcd = (args.use_gcd != '0') |
| 447 args.app_capabilities = set(args.app_capabilities) | 460 args.app_capabilities = set(args.app_capabilities) |
| 448 return buildWebApp(**vars(args)) | 461 return buildWebApp(**vars(args)) |
| 449 | 462 |
| 450 | 463 |
| 451 if __name__ == '__main__': | 464 if __name__ == '__main__': |
| 452 sys.exit(main()) | 465 sys.exit(main()) |
| OLD | NEW |