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

Unified Diff: chrome/common/extensions/docs/server2/manifest_data_source.py

Issue 14273041: Doc server manifest page generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Codereview and polish Created 7 years, 7 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/manifest_data_source.py
diff --git a/chrome/common/extensions/docs/server2/manifest_data_source.py b/chrome/common/extensions/docs/server2/manifest_data_source.py
new file mode 100644
index 0000000000000000000000000000000000000000..daf45963a91e4e3b4bbfc59360ec25ddc848eb9b
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/manifest_data_source.py
@@ -0,0 +1,87 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from collections import defaultdict
+
+from third_party.json_schema_compiler.json_parse import Parse
+
+class ManifestDataSource(object):
+ """ Provides a template with access to manifest properties specific to apps or
+ extensions.
+ """
+ def __init__(self, compiled_fs_factory, local_file_system, manifest_path,
+ features_path, channel):
+ self._manifest_path = manifest_path
+ self._features_path = features_path
+ self._local_file_system = local_file_system
+ self._cache = compiled_fs_factory.Create(
+ self._CreateManifestData, ManifestDataSource)
+ self._channel = channel
+
+ def _ApplyAppsTransformations(self, manifest):
+ manifest['required'][0]['example'] = 'Application'
+ # Force defaultdict to create the 'only_one' list no matter what.
+ manifest['only_one']
+ manifest['optional'][-1]['is_last'] = True
+
+ def _ApplyExtensionsTransformations(self, manifest):
+ manifest['optional'][-1]['is_last'] = True
+
+ def _CreateManifestData(self, _, content):
+ """Take the contents of |_manifest_path| and create apps and extensions
+ versions of a manifest example based on the contents of |_features_path|.
+ """
+ manifest_json = Parse(content)
+ features_json = Parse(self._local_file_system.Read(
not at google - send to devlin 2013/05/11 20:42:04 ReadSingle. And to answer your question in IRC - y
jshumway 2013/05/11 22:08:20 Done.
+ [self._features_path]).Get()[self._features_path])
+ apps = defaultdict(list)
+ extensions = defaultdict(list)
not at google - send to devlin 2013/05/11 18:32:01 defaultdict isn't ordered right? I think that's a
jshumway 2013/05/11 22:08:20 Done.
+
+ def add_property(feature, manifest_key, type_='optional'):
not at google - send to devlin 2013/05/11 18:32:01 just explicitly pass in 'optional' for type_ below
jshumway 2013/05/11 22:08:20 Sorry, that was a poor choice of name.
+ """If |feature|, from features_json, has the correct extension_types, add
+ |manifest_key| to either apps or extensions.
+ """
+ added = False
+
+ if feature['extension_types'] == 'all':
+ apps[type_].append(manifest_key)
+ extensions[type_].append(manifest_key)
+ return True
+ # The following two conditions are not mutually exclusive.
+ if 'platform_app' in feature['extension_types']:
+ apps[type_].append(manifest_key)
+ added = True
+ if 'extension' in feature['extension_types']:
+ extensions[type_].append(manifest_key)
+ added = True
+ return added
not at google - send to devlin 2013/05/11 18:32:01 this could all be more concise: added = False ext
jshumway 2013/05/11 22:08:20 Done.
+
+ # Property types are: required, only_one, recommended, and optional.
+ for property_type in manifest_json:
not at google - send to devlin 2013/05/11 18:32:01 I think my objection to type here is the same.
jshumway 2013/05/11 22:08:20 Done.
+ for manifest_key in manifest_json[property_type]:
+ # If a property is in manifest.json but not _manifest_features, this
+ # will cause an error.
+ feature = features_json[manifest_key['name']]
+ if add_property(feature, manifest_key, property_type):
+ del features_json[manifest_key['name']]
+
+ # All of the properties left in features_json are assumed to be optional.
+ for feature in features_json.keys():
+ item = features_json[feature]
+ # Handles instances where a features entry is a union with a whitelist.
+ if isinstance(item, list):
+ item = item[0]
+ add_property(item, {'name': feature})
+
+ self._ApplyAppsTransformations(apps)
+ self._ApplyExtensionsTransformations(extensions)
+
+ apps['optional'] = sorted(apps['optional'], key=lambda d: d['name'])
not at google - send to devlin 2013/05/11 18:32:01 from operator import itemgetter ... apps['optional
jshumway 2013/05/11 22:08:20 I had never heard of that module before, I have a
+ extensions['optional'] = sorted(
+ extensions['optional'], key=lambda d: d['name'])
+
+ return {'apps': apps, 'extensions': extensions}
+
+ def get(self, key):
+ return self._cache.GetFromFile(self._manifest_path)[key]

Powered by Google App Engine
This is Rietveld 408576698