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

Side by Side 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: more idiomatic/less explicit copying Created 7 years, 4 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 copy import deepcopy
6
7 def Parse(features_json):
8 '''Standardize the raw features file json |features_json| into a more regular
9 format. Return a dictionary of features, keyed by name. Each feature is
10 guaranteed to have a 'name' attribute and a 'platforms' attribute that is a
11 list of platforms the feature is relevant to. Valid platforms are 'app' or
12 'extension'. Other optional keys may be present in each feature.
13
14 Features with a 'whitelist' are only relevant to apps or extensions on that
15 whitelist and are not included in the retured features dictionary.
16 '''
17 features = {}
18
19 for name, value in features_json.iteritems():
20 # Some feature names corrispond to a list; force a list down to a single
21 # feature by removing entries that have a 'whitelist'.
22 if isinstance(value, list):
23 values = [subvalue for subvalue in value if not 'whitelist' in subvalue]
24 if values:
25 value = values[0]
26 else:
27 continue
28
29 if 'whitelist' in value:
30 continue
31
32 features[name] = { 'platforms': [] }
33
34 platforms = value.pop('extension_types')
35 if platforms == 'all' or 'platform_app' in platforms:
36 features[name]['platforms'].append('app')
37 if platforms == 'all' or 'extension' in platforms:
38 features[name]['platforms'].append('extension')
39
40 features[name]['name'] = name
41 features[name].update(value)
42
43 return features
44
45 def Filtered(features, platform=None):
46 '''Create a new features dictionary from |features| that contains only items
47 relevant to |platform|. Items retained are deepcopied. Returns new features
48 dictionary.
49 '''
50 filtered_features = {}
51
52 for name, feature in features.iteritems():
53 if not platform or platform in feature['platforms']:
54 filtered_features[name] = deepcopy(feature)
55
56 return filtered_features
57
58 def MergedWith(features, other):
59 '''Merge |features| with an additional dictionary to create a new features
60 dictionary. If a feature is common to both |features| and |other|, then it is
61 merged using the standard dictionary update instead of being overwritten.
62 Returns the new features dictionary.
63 '''
64 for key, value in other.iteritems():
65 if key in features:
66 features[key].update(value)
67 else:
68 features[key] = value
69
70 return features
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/cron.yaml ('k') | chrome/common/extensions/docs/server2/features_utility_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698