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..948a71b484ca4d53289579d4991b20eec7115c43 100755 |
--- a/chrome/android/webapk/shell_apk/manifest_processor.py |
+++ b/chrome/android/webapk/shell_apk/manifest_processor.py |
@@ -6,23 +6,23 @@ |
"""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 |
-sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, |
- os.pardir, os.pardir, 'build', 'android', 'gyp', |
- 'util')) |
+#Import pystache from //third_party/pystache |
+src_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, |
+ os.pardir, os.pardir) |
+sys.path.append(os.path.join(src_dir, 'third_party')) |
+import pystache |
+sys.path.append(os.path.join(src_dir, '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 +30,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 in 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__': |