Index: chrome/common/extensions/docs/server2/availability_data_source.py |
diff --git a/chrome/common/extensions/docs/server2/availability_data_source.py b/chrome/common/extensions/docs/server2/availability_data_source.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b34c0d52bb51866c21c7d7e823b217606f077107 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/availability_data_source.py |
@@ -0,0 +1,77 @@ |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+from file_system import FileNotFoundError |
+import object_store |
+ |
+class AvailabilityDataSource: |
+ """Uses API data sources generated by a ChromeVersionDataSource in order to |
+ search the filesystem for the earliest existence of a specified API throughout |
+ the different versions of Chrome; this constitutes an API's availability. |
+ """ |
+ |
+ def __init__(self, version_data_source, version, object_store): |
+ self._version_data_source = version_data_source |
+ self._version = version |
+ self._object_store = object_store |
+ |
+ def _CheckExistence(self, api_name, version): |
+ """Tries to 'get' an api from the filesystem, and reports its results |
+ """ |
+ api_data_source = self._version_data_source.GetDataSourceForVersion( |
+ '%s' % version) |
cduvall
2013/03/27 23:01:10
just version? or str(version)?
epeterson
2013/03/28 00:53:50
Done.
|
+ try: |
+ api_data_source.tryGet(api_name) |
+ except FileNotFoundError: |
+ try: |
+ api_data_source.tryGet(api_name, try_non_unix=True) |
+ except FileNotFoundError: |
+ return False |
+ return True |
+ |
+ def FindEarliestAvailability(self, api_name): |
+ """Searches in descending order through filesystem caches tied to specific |
+ chrome version numbers and looks for the existence of a specified api, |
+ |api_name|. When an api is not found, returns the previous version number |
+ (the last known version where the api was found). |
+ """ |
+ availability = self._object_store.Get( |
+ api_name, |
+ object_store.AVAILABILITY_DATA_SOURCE).Get() |
+ |
+ if availability is not None: |
+ return availability |
+ |
+ if self._version == 'trunk': |
+ 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.
|
+ # If the API wasn't found in trunk, then it isn't currently available. |
+ 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
|
+ |
+ if self._version == 'trunk': |
+ latest_version = self._version_data_source.GetLatestVersionNumber() |
+ version_int = latest_version |
+ else: |
+ version_int = int(self._version) |
+ |
+ # Extension APIs are not present in the filesystem before version 18. |
+ while version_int >= 18: |
+ 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.
|
+ break |
+ version_int -= 1 |
+ |
+ version_int += 1 |
+ # If the version number is greater than the current version of Chrome, then |
+ # 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.
|
+ if self._version == 'trunk': |
+ if version_int > latest_version: |
+ availability = 'trunk' |
+ else: |
+ availability = '%d' % version_int |
cduvall
2013/03/27 23:01:10
str(version_int)
epeterson
2013/03/28 00:53:51
Done.
|
+ elif version_int <= int(self._version): |
+ availability = '%d' % version_int |
cduvall
2013/03/27 23:01:10
str(version_int)
epeterson
2013/03/28 00:53:51
Done.
|
+ |
+ self._object_store.Set(api_name, |
+ availability, |
+ object_store.AVAILABILITY_DATA_SOURCE) |
+ return availability |