OLD | NEW |
---|---|
(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 itertools import ifilter | |
6 from operator import itemgetter | |
7 | |
8 from features import Features | |
9 import features_utility | |
10 from third_party.json_schema_compiler.json_parse import Parse | |
11 | |
12 def _ListifyPermissions(permissions): | |
not at google - send to devlin
2013/09/23 18:31:30
this should be in the permission_data_source since
| |
13 '''Filter out any permissions that do not have a description or with a name | |
14 that ends with Private then sort permissions features by name into a list. | |
15 ''' | |
16 def filter_permissions(perm): | |
17 return 'description' in perm and not perm['name'].endswith('Private') | |
18 | |
19 return sorted( | |
20 ifilter(filter_permissions, permissions.values()), | |
21 key=itemgetter('name')) | |
22 | |
23 def _AddDependencyDescriptions(permissions, api_features, template_data_source): | |
24 '''Use |api_features| to determine the dependencies APIs have on |permission|. | |
25 Add a description to the permission based on those dependencies. | |
26 ''' | |
27 for permission in permissions: | |
28 # Don't overwrite the description created by expanding a partial template. | |
29 if 'partial' in permission or not permission['platforms']: | |
30 continue | |
31 has_deps = False | |
32 if name in api_features: | |
33 for dependency in api_features[name].get('dependencies', ()): | |
34 if dependency.startswith('permission:'): | |
35 has_deps = True | |
36 if has_deps: | |
37 permission['partial'] = 'permissions/generic_description' | |
38 | |
39 for permission in permissions: | |
40 # Turn partial templates into descriptions, ensure anchors are set. | |
41 if not 'anchor' in permission: | |
42 permission['anchor'] = permission['name'] | |
43 if 'partial' in permission: | |
44 permission['description'] = self._template_data_source.get( | |
45 permission['partial']) | |
46 del permission['partial'] | |
47 | |
48 class PermissionFeatures(Features): | |
49 '''Subclass of Features to provide permission descriptions derived from API | |
50 dependencies and filter private or undescribed permissions. | |
51 ''' | |
52 def __init__(self, | |
53 compiled_fs_factory, | |
54 permission_features_path, | |
55 file_system, | |
56 permissions_json_path): | |
57 self._file_system = file_system | |
58 self._permissions_json_path = permissions_json_path | |
59 self._template_data_source = None | |
60 super(PermissionFeatures, self).__init__(compiled_fs_factory, | |
61 permission_features_path) | |
62 | |
63 def Parse(self, features_json): | |
64 permissions_json = Parse( | |
65 self._file_system.ReadSingle(self._permissions_json_path)) | |
66 permission_features = features_utility.MergedWith( | |
67 features_utility.Parse(features_json), permissions_json) | |
68 return permission_features | |
69 | |
70 def CreateCache(self, features): | |
71 return { | |
72 'declare_apps': _ListifyPermissions( | |
73 self.FilterByPlatform(features, 'apps')), | |
74 'declare_extensions': _ListifyPermissions( | |
75 self.FilterByPlatform(features, 'extensions')) | |
76 } | |
not at google - send to devlin
2013/09/23 18:31:30
so... this overrides CreateCache from Features?
i
| |
77 | |
78 def AddDependencyDescriptions(self, api_features, template_data_source): | |
79 for platform in ('declare_apps', 'declare_extensions'): | |
80 _AddDependencyDescriptions(self.get(platform), | |
81 api_features, | |
82 template_data_source) | |
OLD | NEW |