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

Side by Side Diff: chrome/common/extensions/docs/server2/features_utility.py

Issue 16410002: Docserver manifest follow up (rewrite) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gen-manifest-try-2
Patch Set: codereview Created 7 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
not at google - send to devlin 2013/07/29 23:30:09 actually I think this should be called FeaturesMod
jshumway 2013/07/30 23:15:50 Done.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 class FeatureFile(object):
not at google - send to devlin 2013/07/29 23:30:09 document what this is, what the keys are, etc.
jshumway 2013/07/30 23:15:50 Done, though I have a little more to add here.
6 def __init__(self, features_json):
not at google - send to devlin 2013/07/29 23:30:09 can we make this class immutable? it's much easier
jshumway 2013/07/30 23:15:50 Done.
7 self._features = {}
8 for name, value in features_json.iteritems():
9 if isinstance(value, list):
10 temp = None
11 for subvalue in value:
12 if not 'whitelist' in subvalue:
13 temp = subvalue
14 break
15 else:
16 continue
17 value = temp
18
19 if 'whitelist' in value:
20 continue
21 self._features[name] = { 'platform': [] }
22
23 platforms = value.pop('extension_types')
24 if platforms == 'all' or 'extension' in platforms:
25 self._features[name]['platform'].append('extension')
26 if platforms == 'all' or 'platform_app' in platforms:
27 self._features[name]['platform'].append('app')
28
29 self._features[name]['name'] = name
30 self._features[name].update(value)
31
32 def Filter(self, platform):
not at google - send to devlin 2013/07/29 23:30:09 since we may want to filter based on other propert
jshumway 2013/07/30 23:15:50 Done.
33 for name in self._features.keys():
34 feature = self._features[name]
35 if not platform in feature['platform']:
36 del self._features[name]
37
38 return self
39
40 def MergeWith(self, other):
41 '''Do a semi-recursive merge. Any keys common to both |self| and |other|
42 will have their dictionary values merged, instead of overwritten.
43 '''
44 for key, value in other.iteritems():
45 if key in self._features:
46 self._features[key].update(value)
47 else:
48 self._features[key] = value
49
50 return self
51
52 def InsertSubDocs(self):
not at google - send to devlin 2013/07/29 23:30:09 perhaps the term children rather than subdocs woul
jshumway 2013/07/30 23:15:50 I'll change it here to RestructureChildren, and ch
53 features = self._features
54 self._features = None
55
56 def add_subdoc(features, parent, subname, value):
57 value['name'] = subname
58 if not 'subdocs' in features[parent]:
59 features[parent]['subdocs'] = {}
60 features[parent]['subdocs'][subname] = value
61
62 def insert_sub_docs(features):
63 for name in features.keys():
64 if '.' in name:
65 value = features.pop(name)
66 parent, subname = name.split('.', 1)
67 add_subdoc(features, parent, subname, value)
68
69 for value in features.values():
70 if 'subdocs' in value:
71 insert_sub_docs(value['subdocs'])
72
73 insert_sub_docs(features)
74 return features
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698