OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 | 6 |
7 from features_model import FeaturesModel | 7 from features_model import FeaturesModel |
8 from third_party.json_schema_compiler.json_parse import Parse | 8 from third_party.json_schema_compiler.json_parse import Parse |
9 | 9 |
10 def _ListifyAndSortDocs(properties, platform): | 10 def _ListifyAndSortDocs(properties, platform): |
11 '''Convert docs into lists and sort them, recursively such that children | 11 '''Convert docs into lists and sort them, recursively such that children |
12 lists are also sorted, first by level, then by name. | 12 lists are also sorted, first by level, then by name. |
13 ''' | 13 ''' |
14 def sort_key(item): | 14 def sort_key(item): |
15 '''Key function to sort items primarily by level (according to index into | 15 '''Key function to sort items primarily by level (according to index into |
16 levels) then subsort by name. | 16 levels) then subsort by name. |
17 ''' | 17 ''' |
18 levels = ('required', 'recommended', 'only_one', 'optional') | 18 levels = ('required', 'recommended', 'only_one', 'optional') |
19 | 19 |
20 return (levels.index(item.get('level', 'optional')), item['name']) | 20 return (levels.index(item.get('level', 'optional')), item.name) |
21 | 21 |
22 def convert_and_sort(properties): | 22 def convert_and_sort(properties): |
23 for key, value in properties.items(): | 23 for key, value in properties.items(): |
24 if 'example' in value: | 24 if 'example' in value: |
25 value['has_example'] = True | 25 value['has_example'] = True |
26 example = json.dumps(value['example']) | 26 example = json.dumps(value['example']) |
27 if example == '{}': | 27 if example == '{}': |
28 value['example'] = '{...}' | 28 value['example'] = '{...}' |
29 elif example == '[]': | 29 elif example == '[]': |
30 value['example'] = '[...]' | 30 value['example'] = '[...]' |
31 else: | 31 else: |
32 value['example'] = example | 32 value['example'] = example |
33 | 33 |
34 if 'children' in value: | 34 if 'children' in value: |
35 properties[key]['children'] = convert_and_sort(value['children']) | 35 properties[key]['children'] = convert_and_sort(value['children']) |
36 | 36 |
37 return sorted(properties.values(), key=sort_key) | 37 return sorted(properties.values(), key=sort_key) |
38 | 38 |
39 # Fix the 'name' manifest property's example. | |
not at google - send to devlin
2013/08/05 22:23:49
I don't know what this means, can you give some co
| |
39 name = properties['name'] | 40 name = properties['name'] |
40 name['example'] = name['example'].replace('{{title}}', platform.capitalize()) | 41 name['example'] = name['example'].replace('{{title}}', platform.capitalize()) |
41 | 42 |
42 return convert_and_sort(properties) | 43 return convert_and_sort(properties) |
43 | 44 |
44 def _AddLevelAnnotations(properties): | 45 def _AddLevelAnnotations(properties): |
45 '''Add level annotations to level groups in a manifest property list and | 46 '''Add level annotations to level groups in a manifest property list and |
46 child lists. Requeries a list of properties sorted by level, with children | 47 child lists. Requeries a list of properties sorted by level, with children |
47 in sorted lists as well. | 48 in sorted lists as well. |
48 | 49 |
(...skipping 26 matching lines...) Expand all Loading... | |
75 annotate('required', properties) | 76 annotate('required', properties) |
76 return properties | 77 return properties |
77 | 78 |
78 def _RestructureChildren(features): | 79 def _RestructureChildren(features): |
79 '''Features whose names are of the form 'parent.child' are moved to be part | 80 '''Features whose names are of the form 'parent.child' are moved to be part |
80 of the 'parent' dictionary under the key 'children'. Names are changed to | 81 of the 'parent' dictionary under the key 'children'. Names are changed to |
81 the 'child' section of the original name. Applied recursively so that | 82 the 'child' section of the original name. Applied recursively so that |
82 children can have children. | 83 children can have children. |
83 ''' | 84 ''' |
84 def add_child(features, parent, child_name, value): | 85 def add_child(features, parent, child_name, value): |
85 value['name'] = child_name | 86 value.name = child_name |
not at google - send to devlin
2013/08/05 22:23:49
So IIRC from our email, the purpose of storing the
| |
86 if not 'children' in features[parent]: | 87 if not 'children' in features[parent]: |
87 features[parent]['children'] = {} | 88 features[parent]['children'] = {} |
88 features[parent]['children'][child_name] = value | 89 features[parent]['children'][child_name] = value |
89 | 90 |
90 def insert_children(features): | 91 def insert_children(features): |
91 for name in features.keys(): | 92 for name in features.keys(): |
92 if '.' in name: | 93 if '.' in name: |
93 value = features.pop(name) | 94 value = features.pop(name) |
94 parent, child_name = name.split('.', 1) | 95 parent, child_name = name.split('.', 1) |
95 add_child(features, parent, child_name, value) | 96 add_child(features, parent, child_name, value) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 manifest_features = ( | 140 manifest_features = ( |
140 FeaturesModel.FromJson(Parse(content)).MergeWith(manifest_json)) | 141 FeaturesModel.FromJson(Parse(content)).MergeWith(manifest_json)) |
141 | 142 |
142 return { | 143 return { |
143 'apps': for_templates(manifest_features, 'app'), | 144 'apps': for_templates(manifest_features, 'app'), |
144 'extensions': for_templates(manifest_features, 'extension') | 145 'extensions': for_templates(manifest_features, 'extension') |
145 } | 146 } |
146 | 147 |
147 def get(self, key): | 148 def get(self, key): |
148 return self._cache.GetFromFile(self._features_path)[key] | 149 return self._cache.GetFromFile(self._features_path)[key] |
OLD | NEW |