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

Side by Side Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 386443003: Docserver: Add 'deprecated since' message for API nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 6 years, 5 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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from copy import copy 5 from copy import copy
6 import logging 6 import logging
7 import os 7 import os
8 import posixpath 8 import posixpath
9 9
10 from data_source import DataSource 10 from data_source import DataSource
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 callback_index = lookup_path.index('callback') 164 callback_index = lookup_path.index('callback')
165 try: 165 try:
166 lookup_path.pop(callback_index) 166 lookup_path.pop(callback_index)
167 node_availability = self._LookupNodeAvailability(lookup_path) 167 node_availability = self._LookupNodeAvailability(lookup_path)
168 finally: 168 finally:
169 lookup_path.insert(callback_index, 'callback') 169 lookup_path.insert(callback_index, 'callback')
170 return node_availability 170 return node_availability
171 return None 171 return None
172 172
173 def _LookupAvailability(self, lookup_path): 173 def _LookupAvailability(self, lookup_path):
174 '''Runs all the lookup checks on self._lookup_path and 174 '''Runs all the lookup checks on |lookup_path| and
175 returns the node availability if found, None otherwise. 175 returns the node availability if found, None otherwise.
176 ''' 176 '''
177 for lookup in (self._LookupNodeAvailability, 177 for lookup in (self._LookupNodeAvailability,
178 self._CheckEventCallback, 178 self._CheckEventCallback,
179 self._CheckNamespacePrefix): 179 self._CheckNamespacePrefix):
180 node_availability = lookup(lookup_path) 180 node_availability = lookup(lookup_path)
181 if node_availability is not None: 181 if node_availability is not None:
182 return node_availability 182 return node_availability
183 return None 183 return None
184 184
(...skipping 18 matching lines...) Expand all
203 # lookup paths like 203 # lookup paths like
204 # 'events > types > Rule > properties > tags > tagsType'. 204 # 'events > types > Rule > properties > tags > tagsType'.
205 # These nodes are treated as properties. 205 # These nodes are treated as properties.
206 return 'properties' 206 return 'properties'
207 if self._lookup_path[0] == 'events': 207 if self._lookup_path[0] == 'events':
208 # HACK(ahernandez.miralles): This catches a few edge cases, 208 # HACK(ahernandez.miralles): This catches a few edge cases,
209 # such as 'webviewTag > events > consolemessage > level'. 209 # such as 'webviewTag > events > consolemessage > level'.
210 return 'properties' 210 return 'properties'
211 raise AssertionError('Could not classify node %s' % self) 211 raise AssertionError('Could not classify node %s' % self)
212 212
213 def GetDeprecated(self):
214 '''Returns when this node became deprecated, or None if it
215 is not deprecated.
216 '''
217 deprecated_path = self._lookup_path + ['deprecated']
218 for lookup in (self._LookupNodeAvailability,
219 self._CheckNamespacePrefix):
220 node_availability = lookup(deprecated_path)
221 if node_availability is not None:
222 return node_availability
223 if 'callback' in self._lookup_path:
224 return self._CheckEventCallback(deprecated_path)
225 return None
226
213 def GetAvailability(self): 227 def GetAvailability(self):
214 '''Returns availability information for this node. 228 '''Returns availability information for this node.
215 ''' 229 '''
216 if self._GetCategory() in self._ignored_categories: 230 if self._GetCategory() in self._ignored_categories:
217 return None 231 return None
218 node_availability = self._LookupAvailability(self._lookup_path) 232 node_availability = self._LookupAvailability(self._lookup_path)
219 if node_availability is None: 233 if node_availability is None:
220 logging.warning('No availability found for: %s' % self) 234 logging.warning('No availability found for: %s' % self)
221 return None 235 return None
222 236
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 # if they share the same 'title' attribute. 562 # if they share the same 'title' attribute.
549 row_titles = [row['title'] for row in intro_rows] 563 row_titles = [row['title'] for row in intro_rows]
550 for misc_row in self._GetMiscIntroRows(): 564 for misc_row in self._GetMiscIntroRows():
551 if misc_row['title'] in row_titles: 565 if misc_row['title'] in row_titles:
552 intro_rows[row_titles.index(misc_row['title'])] = misc_row 566 intro_rows[row_titles.index(misc_row['title'])] = misc_row
553 else: 567 else:
554 intro_rows.append(misc_row) 568 intro_rows.append(misc_row)
555 569
556 return intro_rows 570 return intro_rows
557 571
558 def _GetAvailabilityTemplate(self, status=None, version=None, scheduled=None): 572 def _CreateAvailabilityTemplate(self, status, scheduled, version):
559 '''Returns an object that the templates use to display availability 573 '''Returns an object suitable for use in templates to display availability
560 information. 574 information.
561 ''' 575 '''
562 if status is None:
563 availability_info = self._current_node.GetAvailability()
564 if availability_info is None:
565 return None
566 status = availability_info.channel
567 version = availability_info.version
568 return { 576 return {
569 'partial': self._template_cache.GetFromFile( 577 'partial': self._template_cache.GetFromFile(
570 '%sintro_tables/%s_message.html' % (PRIVATE_TEMPLATES, status)).Get(), 578 '%sintro_tables/%s_message.html' % (PRIVATE_TEMPLATES, status)).Get(),
571 'scheduled': scheduled, 579 'scheduled': scheduled,
572 'version': version 580 'version': version
573 } 581 }
574 582
583 def _GetAvailabilityTemplate(self):
584 '''Gets availability for the current node and returns an appropriate
585 template object.
586 '''
587 # Displaying deprecated status takes precedence over when the API
588 # became stable.
589 availability_info = self._current_node.GetDeprecated()
590 if availability_info is not None:
591 status = 'deprecated'
592 else:
593 availability_info = self._current_node.GetAvailability()
594 if availability_info is None:
595 return None
596 status = availability_info.channel_info.channel
597 return self._CreateAvailabilityTemplate(
598 status,
599 availability_info.scheduled,
600 availability_info.channel_info.version)
601
575 def _GetIntroDescriptionRow(self): 602 def _GetIntroDescriptionRow(self):
576 ''' Generates the 'Description' row data for an API intro table. 603 ''' Generates the 'Description' row data for an API intro table.
577 ''' 604 '''
578 return { 605 return {
579 'title': 'Description', 606 'title': 'Description',
580 'content': [ 607 'content': [
581 { 'text': self._namespace.description } 608 { 'text': self._namespace.description }
582 ] 609 ]
583 } 610 }
584 611
585 def _GetIntroAvailabilityRow(self): 612 def _GetIntroAvailabilityRow(self):
586 ''' Generates the 'Availability' row data for an API intro table. 613 ''' Generates the 'Availability' row data for an API intro table.
587 ''' 614 '''
588 if self._IsExperimental(): 615 if self._IsExperimental():
589 status = 'experimental' 616 status = 'experimental'
617 scheduled = None
590 version = None 618 version = None
591 scheduled = None
592 else: 619 else:
593 status = self._availability.channel_info.channel 620 status = self._availability.channel_info.channel
621 scheduled = self._availability.scheduled
594 version = self._availability.channel_info.version 622 version = self._availability.channel_info.version
595 scheduled = self._availability.scheduled
596 return { 623 return {
597 'title': 'Availability', 624 'title': 'Availability',
598 'content': [ 625 'content': [
599 self._GetAvailabilityTemplate(status=status, 626 self._CreateAvailabilityTemplate(status, scheduled, version)
600 version=version,
601 scheduled=scheduled)
602 ] 627 ]
603 } 628 }
604 629
605 def _GetIntroDependencyRows(self): 630 def _GetIntroDependencyRows(self):
606 # Devtools aren't in _api_features. If we're dealing with devtools, bail. 631 # Devtools aren't in _api_features. If we're dealing with devtools, bail.
607 if 'devtools' in self._namespace.name: 632 if 'devtools' in self._namespace.name:
608 return [] 633 return []
609 634
610 api_feature = self._api_features.Get().get(self._namespace.name) 635 api_feature = self._api_features.Get().get(self._namespace.name)
611 if not api_feature: 636 if not api_feature:
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 getter = lambda: 0 793 getter = lambda: 0
769 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get() 794 getter.get = lambda api_name: self._GetImpl(platform, api_name).Get()
770 return getter 795 return getter
771 796
772 def Cron(self): 797 def Cron(self):
773 futures = [] 798 futures = []
774 for platform in GetPlatforms(): 799 for platform in GetPlatforms():
775 futures += [self._GetImpl(platform, name) 800 futures += [self._GetImpl(platform, name)
776 for name in self._platform_bundle.GetAPIModels(platform).GetNames()] 801 for name in self._platform_bundle.GetAPIModels(platform).GetNames()]
777 return Collect(futures, except_pass=FileNotFoundError) 802 return Collect(futures, except_pass=FileNotFoundError)
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698