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.
5 from itertools
import groupby
6 from operator
import itemgetter
9 from data_source
import DataSource
10 from extensions_paths
import JSON_TEMPLATES
, PUBLIC_TEMPLATES
11 from future
import Future
12 from platform_util
import GetPlatforms
15 class WhatsNewDataSource(DataSource
):
16 ''' This class creates a list of "what is new" by chrome version.
19 def __init__(self
, server_instance
, _
):
20 self
._parse
_cache
= server_instance
.compiled_fs_factory
.ForJson(
21 server_instance
.host_file_system_provider
.GetMaster())
22 self
._object
_store
= server_instance
.object_store_creator
.Create(
24 self
._platform
_bundle
= server_instance
.platform_bundle
26 def _GenerateChangesListWithVersion(self
, platform
, whats_new_json
):
29 'type': change
['type'],
30 'description': change
['description'],
31 'version': change
['version']
32 } for change_id
, change
in whats_new_json
.iteritems()]
34 def _GetAPIVersion(self
, platform
, api_name
):
36 category
= self
._platform
_bundle
.GetAPICategorizer(platform
).GetCategory(
38 if category
== 'chrome':
39 channel_info
= self
._platform
_bundle
.GetAvailabilityFinder(
40 platform
).GetAPIAvailability(api_name
).channel_info
41 channel
= channel_info
.channel
42 if channel
== 'stable':
43 version
= channel_info
.version
46 def _GenerateAPIListWithVersion(self
, platform
):
48 for api_name
, api_model
in self
._platform
_bundle
.GetAPIModels(
49 platform
).IterModels():
50 version
= self
._GetAPIVersion
(platform
, api_name
)
54 'description': api_model
.description
,
59 data
.sort(key
=itemgetter('version'))
62 def _GenerateWhatsNewDict(self
):
63 whats_new_json_future
= self
._parse
_cache
.GetFromFile(
64 posixpath
.join(JSON_TEMPLATES
, 'whats_new.json'))
65 def _MakeDictByPlatform(platform
):
66 whats_new_json
= whats_new_json_future
.Get()
68 apis
= self
._GenerateAPIListWithVersion
(platform
)
69 apis
.extend(self
._GenerateChangesListWithVersion
(platform
,
71 apis
.sort(key
=itemgetter('version'), reverse
=True)
72 for version
, group
in groupby(apis
, key
=itemgetter('version')):
73 whats_new_by_version
= {
77 item_type
= item
['type']
78 if item_type
not in whats_new_by_version
:
79 whats_new_by_version
[item_type
] = []
80 whats_new_by_version
[item_type
].append(item
)
81 platform_list
.append(whats_new_by_version
)
85 return dict((platform
, _MakeDictByPlatform(platform
))
86 for platform
in GetPlatforms())
87 return Future(callback
=resolve
)
89 def _GetCachedWhatsNewData(self
):
90 data
= self
._object
_store
.Get('whats_new_data').Get()
92 data
= self
._GenerateWhatsNewDict
().Get()
93 self
._object
_store
.Set('whats_new_data', data
)
97 return self
._GetCachedWhatsNewData
().get(key
)
99 def Refresh(self
, path
):
100 return self
._GenerateWhatsNewDict
()