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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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 from collections import defaultdict
6
7 from third_party.json_schema_compiler.json_parse import Parse
8
9 class ManifestDataSource(object):
10 """ Provides a template with access to manifest properties specific to apps or
11 extensions.
12 """
13 def __init__(self, compiled_fs_factory, local_file_system, manifest_path,
14 features_path, channel):
15 self._manifest_path = manifest_path
16 self._features_path = features_path
17 self._local_file_system = local_file_system
18 self._cache = compiled_fs_factory.Create(
19 self._CreateManifestData, ManifestDataSource)
20 self._channel = channel
21
22 def _ApplyAppsTransformations(self, manifest):
23 manifest['required'][0]['example'] = 'Application'
24 # Force defaultdict to create the 'only_one' list no matter what.
25 manifest['only_one']
26 manifest['optional'][-1]['is_last'] = True
27
28 def _ApplyExtensionsTransformations(self, manifest):
29 manifest['optional'][-1]['is_last'] = True
30
31 def _CreateManifestData(self, _, content):
32 """Take the contents of |_manifest_path| and create apps and extensions
33 versions of a manifest example based on the contents of |_features_path|.
34 """
35 manifest_json = Parse(content)
36 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.
37 [self._features_path]).Get()[self._features_path])
38 apps = defaultdict(list)
39 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.
40
41 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.
42 """If |feature|, from features_json, has the correct extension_types, add
43 |manifest_key| to either apps or extensions.
44 """
45 added = False
46
47 if feature['extension_types'] == 'all':
48 apps[type_].append(manifest_key)
49 extensions[type_].append(manifest_key)
50 return True
51 # The following two conditions are not mutually exclusive.
52 if 'platform_app' in feature['extension_types']:
53 apps[type_].append(manifest_key)
54 added = True
55 if 'extension' in feature['extension_types']:
56 extensions[type_].append(manifest_key)
57 added = True
58 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.
59
60 # Property types are: required, only_one, recommended, and optional.
61 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.
62 for manifest_key in manifest_json[property_type]:
63 # If a property is in manifest.json but not _manifest_features, this
64 # will cause an error.
65 feature = features_json[manifest_key['name']]
66 if add_property(feature, manifest_key, property_type):
67 del features_json[manifest_key['name']]
68
69 # All of the properties left in features_json are assumed to be optional.
70 for feature in features_json.keys():
71 item = features_json[feature]
72 # Handles instances where a features entry is a union with a whitelist.
73 if isinstance(item, list):
74 item = item[0]
75 add_property(item, {'name': feature})
76
77 self._ApplyAppsTransformations(apps)
78 self._ApplyExtensionsTransformations(extensions)
79
80 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
81 extensions['optional'] = sorted(
82 extensions['optional'], key=lambda d: d['name'])
83
84 return {'apps': apps, 'extensions': extensions}
85
86 def get(self, key):
87 return self._cache.GetFromFile(self._manifest_path)[key]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698