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

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

Issue 16410002: Docserver manifest follow up (rewrite) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gen-manifest-try-2
Patch Set: Small URL change Created 7 years, 6 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
1 # Copyright 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from collections import OrderedDict 5 from collections import OrderedDict
6 from copy import deepcopy 6 from copy import deepcopy
7 from operator import itemgetter 7 from operator import itemgetter
8 8
9 from third_party.json_schema_compiler.json_parse import Parse 9 from third_party.json_schema_compiler.json_parse import Parse
10 10
11 _PROPERTY_STATUSES = ('required', 'only_one', 'recommended', 'optional')
12
11 class ManifestDataSource(object): 13 class ManifestDataSource(object):
12 """ Provides a template with access to manifest properties specific to apps or 14 """ Provides a template with access to manifest properties specific to apps or
13 extensions. 15 extensions.
14 """ 16 """
15 def __init__(self, 17 def __init__(self,
16 compiled_fs_factory, 18 compiled_fs_factory,
17 file_system, 19 file_system,
18 manifest_path, 20 manifest_path,
19 features_path): 21 features_path):
20 self._manifest_path = manifest_path 22 self._manifest_path = manifest_path
21 self._features_path = features_path 23 self._features_path = features_path
22 self._file_system = file_system 24 self._file_system = file_system
23 self._cache = compiled_fs_factory.Create( 25 self._cache = compiled_fs_factory.Create(
24 self._CreateManifestData, ManifestDataSource) 26 self._CreateManifestData, ManifestDataSource)
25 27
26 def _ApplyAppsTransformations(self, manifest): 28 def _ApplyAppsTransformations(self, manifest):
27 manifest['required'][0]['example'] = 'Application' 29 manifest['required'][0]['example'] = {'value': 'Application'}
28 manifest['optional'][-1]['is_last'] = True 30 manifest['optional'][-1]['is_last'] = True
29 31
30 def _ApplyExtensionsTransformations(self, manifest): 32 def _ApplyExtensionsTransformations(self, manifest):
31 manifest['optional'][-1]['is_last'] = True 33 manifest['optional'][-1]['is_last'] = True
32 34
35 def _InsertSubDocs(self, manifest_dict):
36 """ Insert all docs in the 'subdoc' category into their 'parent' objcets,
not at google - send to devlin 2013/07/02 18:23:11 objcets also """ -> ''' oh damn they're all like
jshumway 2013/07/24 17:40:07 Rewrote pretty much the entire file, so it should
37 determined by the section of the subdocs name before a period. Only nests
38 one level.
39 """
40 for key in manifest_dict.get('subdoc', []):
41 parent_name, doc_name = key['name'].split('.', 1)
42 key['name'] = doc_name
43 for category in _PROPERTY_STATUSES:
44 for entry in manifest_dict[category]:
45 if parent_name == entry['name']:
46 parent = entry
47
48 assert parent
49 if 'subdoc' in parent:
50 parent['subdoc'].append(key)
51 else:
52 parent['subdoc'] = [key]
53
54 del manifest_dict['subdoc']
55
33 def _CreateManifestData(self, _, content): 56 def _CreateManifestData(self, _, content):
34 """Take the contents of |_manifest_path| and create apps and extensions 57 """ Take the contents of |_manifest_path| and create apps and extensions
35 versions of a manifest example based on the contents of |_features_path|. 58 versions of a manifest example based on the contents of |_features_path|.
36 """ 59 """
37 def create_manifest_dict(): 60 def create_manifest_dict():
38 d = OrderedDict() 61 d = OrderedDict()
39 for category in ['required', 'only_one', 'recommended', 'optional']: 62 for category in _PROPERTY_STATUSES + ('subdoc',):
40 d[category] = [] 63 d[category] = []
41 return d 64 return d
42 65
43 apps = create_manifest_dict() 66 apps = create_manifest_dict()
44 extensions = create_manifest_dict() 67 extensions = create_manifest_dict()
45 68
46 manifest_json = Parse(content) 69 manifest_json = Parse(content)
47 features_json = Parse(self._file_system.ReadSingle( 70 features_json = Parse(self._file_system.ReadSingle(
48 self._features_path)) 71 self._features_path))
49 72
50 def add_property(feature, manifest_key, category): 73 def add_property(feature, manifest_key, category):
51 """If |feature|, from features_json, has the correct extension_types, add 74 """ If |feature|, from features_json, has the correct extension_types, add
52 |manifest_key| to either apps or extensions. 75 |manifest_key| to either apps or extensions.
53 """ 76 """
77 # Save the subdocs for later by putting them in their own category.
78 category = 'subdoc' if '.' in manifest_key['name'] else category
79
54 added = False 80 added = False
55 extension_types = feature['extension_types'] 81 extension_types = feature['extension_types']
56 if extension_types == 'all' or 'platform_app' in extension_types: 82 if extension_types == 'all' or 'platform_app' in extension_types:
57 apps[category].append(deepcopy(manifest_key)) 83 apps[category].append(deepcopy(manifest_key))
58 added = True 84 added = True
59 if extension_types == 'all' or 'extension' in extension_types: 85 if extension_types == 'all' or 'extension' in extension_types:
60 extensions[category].append(deepcopy(manifest_key)) 86 extensions[category].append(deepcopy(manifest_key))
61 added = True 87 added = True
62 return added 88 return added
63 89
(...skipping 10 matching lines...) Expand all
74 for feature in features_json.keys(): 100 for feature in features_json.keys():
75 item = features_json[feature] 101 item = features_json[feature]
76 # Handles instances where a features entry is a union with a whitelist. 102 # Handles instances where a features entry is a union with a whitelist.
77 if isinstance(item, list): 103 if isinstance(item, list):
78 item = item[0] 104 item = item[0]
79 add_property(item, {'name': feature}, 'optional') 105 add_property(item, {'name': feature}, 'optional')
80 106
81 apps['optional'].sort(key=itemgetter('name')) 107 apps['optional'].sort(key=itemgetter('name'))
82 extensions['optional'].sort(key=itemgetter('name')) 108 extensions['optional'].sort(key=itemgetter('name'))
83 109
110 self._InsertSubDocs(extensions)
111 self._InsertSubDocs(apps)
112
84 self._ApplyAppsTransformations(apps) 113 self._ApplyAppsTransformations(apps)
85 self._ApplyExtensionsTransformations(extensions) 114 self._ApplyExtensionsTransformations(extensions)
not at google - send to devlin 2013/07/02 18:23:11 how about this: apps['required'][0]['example'] =
jshumway 2013/07/24 17:40:07 Done.
86 115
87 return {'apps': apps, 'extensions': extensions} 116 return {'apps': apps, 'extensions': extensions}
88 117
89 def get(self, key): 118 def get(self, key):
90 return self._cache.GetFromFile(self._manifest_path)[key] 119 return self._cache.GetFromFile(self._manifest_path)[key]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698