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 3# found in the LICENSE file. 4 5''' 6Provides a Manifest Feature abstraction, similar to but more strict than the 7Feature schema (see feature_utility.py). 8 9Each Manifest Feature has a 'level' in addition to the keys defined in a 10Feature. 'level' can be 'required', 'only_one', 'recommended', or 'optional', 11indicating how an app or extension should define a manifest property. If 'level' 12is missing, 'optional' is assumed. 13''' 14 15def ConvertDottedKeysToNested(features): 16 '''Some Manifest Features are subordinate to others, such as app.background to 17 app. Subordinate Features can be moved inside the parent Feature under the key 18 'children'. 19 20 Modifies |features|, a Manifest Features dictionary, by moving subordinate 21 Features with names of the form 'parent.child' into the 'parent' Feature. 22 Child features are renamed to the 'child' section of their previous name. 23 24 Applied recursively so that children can be nested arbitrarily. 25 ''' 26 def add_child(features, parent, child_name, value): 27 value['name'] = child_name 28 if not 'children' in features[parent]: 29 features[parent]['children'] = {} 30 features[parent]['children'][child_name] = value 31 32 def insert_children(features): 33 for name in features.keys(): 34 if '.' in name: 35 value = features.pop(name) 36 parent, child_name = name.split('.', 1) 37 add_child(features, parent, child_name, value) 38 39 for value in features.values(): 40 if 'children' in value: 41 insert_children(value['children']) 42 43 insert_children(features) 44 return features 45