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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/features_utility.py
diff --git a/chrome/common/extensions/docs/server2/features_utility.py b/chrome/common/extensions/docs/server2/features_utility.py
new file mode 100644
index 0000000000000000000000000000000000000000..011132dcbc2371cdc9908633a9bf796d75f1f0ef
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/features_utility.py
@@ -0,0 +1,74 @@
+# 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.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+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.
+ 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.
+ self._features = {}
+ for name, value in features_json.iteritems():
+ if isinstance(value, list):
+ temp = None
+ for subvalue in value:
+ if not 'whitelist' in subvalue:
+ temp = subvalue
+ break
+ else:
+ continue
+ value = temp
+
+ if 'whitelist' in value:
+ continue
+ self._features[name] = { 'platform': [] }
+
+ platforms = value.pop('extension_types')
+ if platforms == 'all' or 'extension' in platforms:
+ self._features[name]['platform'].append('extension')
+ if platforms == 'all' or 'platform_app' in platforms:
+ self._features[name]['platform'].append('app')
+
+ self._features[name]['name'] = name
+ self._features[name].update(value)
+
+ 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.
+ for name in self._features.keys():
+ feature = self._features[name]
+ if not platform in feature['platform']:
+ del self._features[name]
+
+ return self
+
+ def MergeWith(self, other):
+ '''Do a semi-recursive merge. Any keys common to both |self| and |other|
+ will have their dictionary values merged, instead of overwritten.
+ '''
+ for key, value in other.iteritems():
+ if key in self._features:
+ self._features[key].update(value)
+ else:
+ self._features[key] = value
+
+ return self
+
+ 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
+ features = self._features
+ self._features = None
+
+ def add_subdoc(features, parent, subname, value):
+ value['name'] = subname
+ if not 'subdocs' in features[parent]:
+ features[parent]['subdocs'] = {}
+ features[parent]['subdocs'][subname] = value
+
+ def insert_sub_docs(features):
+ for name in features.keys():
+ if '.' in name:
+ value = features.pop(name)
+ parent, subname = name.split('.', 1)
+ add_subdoc(features, parent, subname, value)
+
+ for value in features.values():
+ if 'subdocs' in value:
+ insert_sub_docs(value['subdocs'])
+
+ insert_sub_docs(features)
+ return features

Powered by Google App Engine
This is Rietveld 408576698