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
14 class WhatsNewDataSource(DataSource
):
15 ''' This class creates a list of "what is new" by chrome version.
18 def __init__(self
, server_instance
, _
):
19 self
._parse
_cache
= server_instance
.compiled_fs_factory
.ForJson(
20 server_instance
.host_file_system_provider
.GetTrunk())
21 self
._object
_store
= server_instance
.object_store_creator
.Create(
23 self
._api
_models
= server_instance
.api_models
24 self
._availability
_finder
= server_instance
.availability_finder
25 self
._api
_categorizer
= server_instance
.api_categorizer
27 def _GenerateChangesListWithVersion(self
, platform
, whats_new_json
):
30 'type': change
['type'],
31 'description': change
['description'],
32 'version': change
['version']
33 } for change_id
, change
in whats_new_json
.iteritems()]
35 def _GetApiVersion(self
, platform
, api_name
):
37 category
= self
._api
_categorizer
.GetCategory(platform
, api_name
)
38 if category
== 'chrome':
39 channel_info
= self
._availability
_finder
.GetApiAvailability(api_name
)
40 channel
= channel_info
.channel
41 if channel
== 'stable':
42 version
= channel_info
.version
45 def _GenerateApiListWithVersion(self
, platform
):
47 for api_name
, api_model
in self
._api
_models
.IterModels():
48 version
= self
._GetApiVersion
(platform
, api_name
)
52 'description': api_model
.description
,
57 data
.sort(key
=itemgetter('version'))
60 def _GenerateWhatsNewDict(self
):
61 whats_new_json_future
= self
._parse
_cache
.GetFromFile(
62 posixpath
.join(JSON_TEMPLATES
, 'whats_new.json'))
63 def _MakeDictByPlatform(platform
):
64 whats_new_json
= whats_new_json_future
.Get()
66 apis
= self
._GenerateApiListWithVersion
(platform
)
67 apis
.extend(self
._GenerateChangesListWithVersion
(platform
,
69 apis
.sort(key
=itemgetter('version'), reverse
=True)
70 for version
, group
in groupby(apis
, key
=itemgetter('version')):
71 whats_new_by_version
= {
75 item_type
= item
['type']
76 if item_type
not in whats_new_by_version
:
77 whats_new_by_version
[item_type
] = []
78 whats_new_by_version
[item_type
].append(item
)
79 platform_list
.append(whats_new_by_version
)
84 'apps': _MakeDictByPlatform('apps'),
85 'extensions': _MakeDictByPlatform('extensions')
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
)
100 return self
._GenerateWhatsNewDict
()