| Index: chrome/android/webapk/shell_apk/manifest_processor.py
|
| diff --git a/chrome/android/webapk/shell_apk/manifest_processor.py b/chrome/android/webapk/shell_apk/manifest_processor.py
|
| index f51f5a41bcaa60bb92ee72eb36494652e288b6ed..591b0aa9a23b14de4e1bb52d832f39948aa337c4 100755
|
| --- a/chrome/android/webapk/shell_apk/manifest_processor.py
|
| +++ b/chrome/android/webapk/shell_apk/manifest_processor.py
|
| @@ -6,23 +6,24 @@
|
|
|
| """Expands the ShellApk's AndroidManifest.xml using Mustache template engine."""
|
|
|
| -import codecs
|
| import argparse
|
| +import codecs
|
| +import json
|
| import os
|
| import sys
|
|
|
| -# Import motemplate from third_party/motemplate
|
| -sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
|
| - os.pardir, os.pardir, 'third_party', 'motemplate'))
|
| -import motemplate
|
| +#Import pystache from third_party/pystache
|
| +sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir,
|
| + 'third_party', 'pystache'))
|
| +import pystache
|
| sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
|
| os.pardir, os.pardir, 'build', 'android', 'gyp',
|
| 'util'))
|
| import build_utils
|
|
|
|
|
| -def _ParseVariables(variables_arg, error_func):
|
| - variables = {}
|
| +def _AppendParsedVariables(initial_variable_list, variables_arg, error_func):
|
| + variables = initial_variable_list
|
| for v in build_utils.ParseGnList(variables_arg):
|
| if '=' not in v:
|
| error_func('--variables argument must contain "=": ' + v)
|
| @@ -30,33 +31,31 @@ def _ParseVariables(variables_arg, error_func):
|
| variables[name] = value
|
| return variables
|
|
|
| -
|
| -'''
|
| -Rewrite conditional sections to be 'Verted Sections' as defined in handlerbars.
|
| -This allows variables to be used in the AndroidManifest to conditionally define
|
| -include segments.
|
| -'''
|
| -def _RewriteConditionals(template_text):
|
| - return template_text.replace('{{#', '{{?')
|
| -
|
| -
|
| def main():
|
| parser = argparse.ArgumentParser()
|
| parser.add_argument('--template', required=True,
|
| help='The template file to process.')
|
| + parser.add_argument('--config_file', required=True,
|
| + help='JSON file with values to put into template.')
|
| parser.add_argument('--output', required=True,
|
| help='The output file to generate.')
|
| - parser.add_argument('--variables', help='Variables to be made available in '
|
| - 'the template processing environment, as a GN list '
|
| - '(e.g. --variables "channel=beta mstone=39")', default='')
|
| + parser.add_argument('--extra_variables', help='Variables to be made '
|
| + 'available the template processing environment (in '
|
| + 'addition to those specified in config file), as a GN '
|
| + 'list (e.g. --extra_variables "channel=beta mstone=39")',
|
| + default='')
|
| options = parser.parse_args()
|
|
|
| - variables = _ParseVariables(options.variables, parser.error)
|
| + variables = {}
|
| + with open(options.config_file, 'r') as f:
|
| + variables = json.loads(f.read())
|
| + variables = _AppendParsedVariables(variables, options.extra_variables,
|
| + parser.error)
|
| +
|
| with open(options.template, 'r') as f:
|
| - template = motemplate.Motemplate(_RewriteConditionals(f.read()))
|
| - render = template.render(variables)
|
| + render = pystache.render(f.read(), variables)
|
| with codecs.open(options.output, 'w', 'utf-8') as output_file:
|
| - output_file.write(render.text)
|
| + output_file.write(render)
|
|
|
|
|
| if __name__ == '__main__':
|
|
|