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 from itertools
import groupby
5 from operator
import itemgetter
7 from data_source
import DataSource
8 from extensions_paths
import JSON_TEMPLATES
9 from extensions_paths
import PUBLIC_TEMPLATES
10 from future
import Gettable
, Future
13 class WhatsNewDataSource(DataSource
):
14 ''' This class creates a list of "what is new" by chrome version.
17 def __init__(self
, server_instance
, _
):
18 self
._parse
_cache
= server_instance
.compiled_fs_factory
.ForJson(
19 server_instance
.host_file_system_provider
.GetTrunk())
20 self
._object
_store
= server_instance
.object_store_creator
.Create(
22 self
._api
_models
= server_instance
.api_models
23 self
._availability
_finder
= server_instance
.availability_finder
24 self
._api
_categorizer
= server_instance
.api_categorizer
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
._api
_categorizer
.GetCategory(platform
, api_name
)
37 if category
== 'chrome':
38 channel_info
= self
._availability
_finder
.GetApiAvailability(api_name
)
39 channel
= channel_info
.channel
40 if channel
== 'stable':
41 version
= channel_info
.version
44 def _GenerateApiListWithVersion(self
, platform
):
46 for api_name
, api_model
in self
._api
_models
.IterModels():
47 version
= self
._GetApiVersion
(platform
, api_name
)
51 'description': api_model
.description
,
56 data
.sort(key
=itemgetter('version'))
59 def _GenerateWhatsNewDict(self
):
60 whats_new_json_future
= self
._parse
_cache
.GetFromFile(
61 '%s/whats_new.json' % JSON_TEMPLATES
)
62 def _MakeDictByPlatform(platform
):
63 whats_new_json
= whats_new_json_future
.Get()
65 apis
= self
._GenerateApiListWithVersion
(platform
)
66 apis
.extend(self
._GenerateChangesListWithVersion
(platform
,
68 apis
.sort(key
=itemgetter('version'), reverse
=True)
69 for version
, group
in groupby(apis
, key
=itemgetter('version')):
70 whats_new_by_version
= {
74 item_type
= item
['type']
75 if item_type
not in whats_new_by_version
:
76 whats_new_by_version
[item_type
] = []
77 whats_new_by_version
[item_type
].append(item
)
78 platform_list
.append(whats_new_by_version
)
83 'apps': _MakeDictByPlatform('apps'),
84 'extensions': _MakeDictByPlatform('extensions')
86 return Future(delegate
=Gettable(resolve
))
88 def _GetCachedWhatsNewData(self
):
89 data
= self
._object
_store
.Get('whats_new_data').Get()
91 data
= self
._GenerateWhatsNewDict
().Get()
92 self
._object
_store
.Set('whats_new_data', data
)
96 return self
._GetCachedWhatsNewData
().get(key
)
99 return self
._GenerateWhatsNewDict
()