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..431cdce049589d7de8321d04c6784fbbf559f12c |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/availability_data_source.py |
@@ -0,0 +1,54 @@ |
+# 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: |
cduvall
2013/03/25 22:59:43
Class level comment about what this does.
epeterson
2013/03/27 22:36:09
Done.
|
+ def __init__(self, |
+ version_data_source, |
+ version_number, |
+ object_store): |
+ self._version_data_source = version_data_source |
+ self._version_number = version_number |
+ self._object_store = object_store |
+ |
+ 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). |
+ """ |
+ version = self._object_store.Get( |
+ api_name, |
+ object_store.AVAILABILITY_DATA_SOURCE).Get() |
+ |
+ if version is not None: |
+ return version |
+ |
+ version_number = int(self._version_number) |
+ # extension api's are not present before version 18 |
cduvall
2013/03/25 22:59:43
Full sentence with proper punctuation for all comm
epeterson
2013/03/27 22:36:09
Done.
|
+ while version_number >= 18: |
+ api_data_source = self._version_data_source.GetDataSourceForVersion( |
+ '%d' % version_number) |
+ try: |
+ api_data_source.tryGet(api_name) |
+ except FileNotFoundError: |
+ try: |
+ api_data_source.tryGet(api_name, try_non_unix=True) |
+ except FileNotFoundError: |
+ break |
+ version_number -= 1 |
+ |
+ version_number += 1 |
+ # if version_number is greater than self._version_number, then the api was |
+ # not found in the current version |
+ if version_number > self._version_number: |
+ version = 'Not available yet' |
+ else: |
+ version = '%d' % version_number |
+ self._object_store.Set(api_name, |
+ version, |
+ object_store.AVAILABILITY_DATA_SOURCE) |
+ return version |