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

Unified Diff: chrome/android/webapk/shell_apk/manifest_processor.py

Issue 2956193002: [Android] Enable WebAPK to have multiple intent filters (Closed)
Patch Set: Merge branch 'rewriting0' into rewriting Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
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..f992581c64df8431035f9a505a8e97be98d2af0c 100755
--- a/chrome/android/webapk/shell_apk/manifest_processor.py
+++ b/chrome/android/webapk/shell_apk/manifest_processor.py
@@ -4,14 +4,21 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Expands the ShellApk's AndroidManifest.xml using Mustache template engine."""
+"""
+Expands the ShellApk's AndroidManifest.xml using Motemplate template engine.
+
+To convert Motemplate to "Mustache template" replace:
Yaron 2017/06/28 18:47:54 Oh I just saw that explicitly called this out :/
+1) {{#section:section}} with {{#section}}
+2) {{section.key}} with {{key}}
+"""
-import codecs
import argparse
+import codecs
+import json
import os
import sys
-# Import motemplate from third_party/motemplate
+#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
@@ -21,8 +28,8 @@ sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
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,30 +37,29 @@ 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()))
+ template = motemplate.Motemplate(f.read())
render = template.render(variables)
with codecs.open(options.output, 'w', 'utf-8') as output_file:
output_file.write(render.text)

Powered by Google App Engine
This is Rietveld 408576698