3 # Copyright (C) 2012 The Android Open Source Project
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
21 def break_lines(key, val):
22 # these don't get split
23 if key in ("PRODUCT_MODEL"):
25 return (key, "\n".join(val.split()))
28 words = line.split("=", 1)
32 return (words[0], words[1])
37 return "\n".join(lines)
39 def parse_variables(lines):
40 return [split_line(line) for line in lines if line.strip()]
42 def render_variables(variables):
43 variables = dict(variables)
45 variables = list(variables.iteritems())
46 variables.sort(lambda a, b: cmp(a[0], b[0]))
47 return ("<table id='variables'>"
48 + "\n".join([ "<tr><th>%(key)s</th><td>%(val)s</td></tr>" % { "key": key, "val": val }
49 for key,val in variables])
52 def linkify_inherit(variables, text, func_name):
53 groups = re.split("(\\$\\(call " + func_name + ",.*\\))", text)
55 for i in range(0,len(groups)/2):
57 result = result + groups[i]
59 href = s.split(",", 1)[1].strip()[:-1]
60 href = href.replace("$(SRC_TARGET_DIR)", "build/target")
61 href = ("../" * variables["FILE"].count("/")) + href + ".html"
62 result = result + "<a href=\"%s\">%s</a>" % (href,s)
63 result = result + groups[-1]
66 def render_original(variables, text):
67 text = linkify_inherit(variables, text, "inherit-product")
68 text = linkify_inherit(variables, text, "inherit-product-if-exists")
79 lines = sys.stdin.readlines()
80 variables = parse_variables(lines)
82 # format the variables
83 variables = [break_lines(key,val) for key,val in variables]
86 variables = dict(variables)
92 "PRODUCT_FACTORY_RAMDISK_MODULES",
93 "PRODUCT_PROPERTY_OVERRIDES",
96 for key in sorted_vars:
97 variables[key] = sort_lines(variables[key])
100 original = read_file(variables["FILE"])
103 values = dict(variables)
105 "variables": render_variables(variables),
106 "original": render_original(variables, original),
112 <title>%(FILE)s</title>
113 <style type="text/css">
115 font-family: Helvetica, Arial, sans-serif;
116 padding-bottom: 20px;
119 border-collapse: collapse;
121 #variables th, #variables td {
124 border-top: 1px solid #c5cdde;
125 border-bottom: 1px solid #c5cdde;
126 padding: 2px 10px 2px 10px;
130 background-color: #e2ecff
133 background-color: #ebf2ff;
138 background-color: #ebf2ff;
139 border-top: 1px solid #c5cdde;
140 border-bottom: 1px solid #c5cdde;
141 padding: 2px 10px 2px 10px;
149 <a href="#Original">Original</a>
150 <a href="#Variables">Variables</a>
151 <h2><a name="Original"></a>Original</h2>
152 <div id="original">%(original)s</div>
153 <h2><a name="Variables"></a>Variables</h2>
159 if __name__ == "__main__":