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

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

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating .idl and .json APIs, HTML intro tables, python files Created 7 years, 8 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 (c) 2012 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 file_system import FileNotFoundError
6 import object_store
7
8 class AvailabilityDataSource:
9 """Uses API data sources generated by a ChromeVersionDataSource in order to
10 search the filesystem for the earliest existence of a specified API throughout
11 the different versions of Chrome; this constitutes an API's availability.
12 """
13
14 def __init__(self, version_data_source, version, object_store):
15 self._version_data_source = version_data_source
16 self._version = version
17 self._object_store = object_store
18
19 def _CheckExistence(self, api_name, version):
20 """Tries to 'get' an api from the filesystem, and reports its results
21 """
22 api_data_source = self._version_data_source.GetDataSourceForVersion(
23 '%s' % version)
cduvall 2013/03/27 23:01:10 just version? or str(version)?
epeterson 2013/03/28 00:53:50 Done.
24 try:
25 api_data_source.tryGet(api_name)
26 except FileNotFoundError:
27 try:
28 api_data_source.tryGet(api_name, try_non_unix=True)
29 except FileNotFoundError:
30 return False
31 return True
32
33 def FindEarliestAvailability(self, api_name):
34 """Searches in descending order through filesystem caches tied to specific
35 chrome version numbers and looks for the existence of a specified api,
36 |api_name|. When an api is not found, returns the previous version number
37 (the last known version where the api was found).
38 """
39 availability = self._object_store.Get(
40 api_name,
41 object_store.AVAILABILITY_DATA_SOURCE).Get()
42
43 if availability is not None:
44 return availability
45
46 if self._version == 'trunk':
47 if self._CheckExistence(api_name, 'trunk') is False:
cduvall 2013/03/27 23:01:10 if not self._CheckExistence(api_name, 'trunk'):
epeterson 2013/03/28 00:53:50 Done.
48 # If the API wasn't found in trunk, then it isn't currently available.
49 return None
cduvall 2013/03/27 23:01:10 Cache this so we don't try to keep looking.
epeterson 2013/03/28 00:53:50 If I cache a None value, it willfail the above che
50
51 if self._version == 'trunk':
52 latest_version = self._version_data_source.GetLatestVersionNumber()
53 version_int = latest_version
54 else:
55 version_int = int(self._version)
56
57 # Extension APIs are not present in the filesystem before version 18.
58 while version_int >= 18:
59 if self._CheckExistence(api_name, '%s' % version_int) is False:
cduvall 2013/03/27 23:01:10 if not ... str(version_int)
epeterson 2013/03/28 00:53:50 Done.
60 break
61 version_int -= 1
62
63 version_int += 1
64 # If the version number is greater than the current version of Chrome, then
65 # the api was not found in the current version.
cduvall 2013/03/27 23:01:10 capitalize API
epeterson 2013/03/28 00:53:50 Done.
66 if self._version == 'trunk':
67 if version_int > latest_version:
68 availability = 'trunk'
69 else:
70 availability = '%d' % version_int
cduvall 2013/03/27 23:01:10 str(version_int)
epeterson 2013/03/28 00:53:51 Done.
71 elif version_int <= int(self._version):
72 availability = '%d' % version_int
cduvall 2013/03/27 23:01:10 str(version_int)
epeterson 2013/03/28 00:53:51 Done.
73
74 self._object_store.Set(api_name,
75 availability,
76 object_store.AVAILABILITY_DATA_SOURCE)
77 return availability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698