diff options
Diffstat (limited to 'chrome/common/extensions/docs/server2/new_github_file_system.py')
-rw-r--r-- | chrome/common/extensions/docs/server2/new_github_file_system.py | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/chrome/common/extensions/docs/server2/new_github_file_system.py b/chrome/common/extensions/docs/server2/new_github_file_system.py index 8ac2ba4..5739585 100644 --- a/chrome/common/extensions/docs/server2/new_github_file_system.py +++ b/chrome/common/extensions/docs/server2/new_github_file_system.py @@ -10,8 +10,9 @@ from zipfile import BadZipfile, ZipFile import appengine_blobstore as blobstore from appengine_url_fetcher import AppEngineUrlFetcher from appengine_wrappers import urlfetch +from docs_server_utils import StringIdentity from file_system import FileNotFoundError, FileSystem, StatInfo -from future import Future +from future import Future, Gettable from object_store_creator import ObjectStoreCreator import url_constants @@ -26,19 +27,9 @@ def _LoadCredentials(object_store_creator): app_version=None, category='password', start_empty=False) - # return 'test_username', 'test_password' password_data = password_store.GetMulti(('username', 'password')).Get() - return password_data.get('username'), password_data.get('password') - -class _Gettable(object): - '''Wrap a callable |f| such that calling .Get on a _Gettable is the same as - calling |f| directly. - ''' - def __init__(self, f, *args): - self._g = lambda: f(*args) - def Get(self): - return self._g() + return password_data.get('username'), password_data.get('password') class GithubFileSystem(FileSystem): @@ -57,7 +48,7 @@ class GithubFileSystem(FileSystem): AppEngineUrlFetcher) @staticmethod - def ForTest(repo, fake_fetcher, path=None): + def ForTest(repo, fake_fetcher, path=None, object_store_creator=None): '''Creates a GithubFIleSystem that can be used for testing. It reads zip files and commit data from server2/test_data/github_file_system/test_owner instead of github.com. It reads from files specified by |repo|. @@ -66,7 +57,7 @@ class GithubFileSystem(FileSystem): path if path is not None else 'test_data/github_file_system', 'test_owner', repo, - ObjectStoreCreator.ForTest(), + object_store_creator or ObjectStoreCreator.ForTest(), fake_fetcher) def __init__(self, base_url, owner, repo, object_store_creator, Fetcher): @@ -105,7 +96,10 @@ class GithubFileSystem(FileSystem): result = self._fetcher.Fetch( 'commits/HEAD', username=self._username, password=self._password) - return json.loads(result.content)['commit']['tree']['sha'] + try: + return json.loads(result.content)['commit']['tree']['sha'] + except (KeyError, ValueError): + logging.warn('Error parsing JSON from repo %s' % self._repo_url) def Refresh(self): '''Compares the cached and live stat versions to see if the cached @@ -141,7 +135,7 @@ class GithubFileSystem(FileSystem): if version != self._stat_cache.Get('stat').Get(): fetch = self._fetcher.FetchAsync( 'zipball', username=self._username, password=self._password) - return Future(delegate=_Gettable(lambda: persist_fetch(fetch))) + return Future(delegate=Gettable(lambda: persist_fetch(fetch))) return Future(value=None) @@ -204,5 +198,8 @@ class GithubFileSystem(FileSystem): return StatInfo(version, child_paths or None) + def GetDebugString(self): + return ' %s: %s' % (self._repo_key, self._repo_url) + def GetIdentity(self): - return '%s(%s)' % (self.__class__.__name__, self._repo_key) + return '%s' % StringIdentity(self.__class__.__name__ + self._repo_key) |