OLD | NEW |
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 import json | 5 import json |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 | 8 |
9 import appengine_blobstore as blobstore | 9 import appengine_blobstore as blobstore |
10 from appengine_wrappers import GetAppVersion, urlfetch | 10 from appengine_wrappers import GetAppVersion, urlfetch |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return None | 60 return None |
61 | 61 |
62 self._blobstore.Set(_MakeBlobstoreKey(self._key_to_set), | 62 self._blobstore.Set(_MakeBlobstoreKey(self._key_to_set), |
63 blob, | 63 blob, |
64 blobstore.BLOBSTORE_GITHUB) | 64 blobstore.BLOBSTORE_GITHUB) |
65 return return_zip | 65 return return_zip |
66 | 66 |
67 class GithubFileSystem(FileSystem): | 67 class GithubFileSystem(FileSystem): |
68 """FileSystem implementation which fetches resources from github. | 68 """FileSystem implementation which fetches resources from github. |
69 """ | 69 """ |
70 def __init__(self, fetcher, blobstore): | 70 def __init__(self, fetcher, blobstore, object_store_creator_factory): |
71 # The password store is the same for all branches and versions. | 71 # The password store is the same for all branches and versions. Don't use |
72 password_store = (ObjectStoreCreator.GlobalFactory() | 72 # |object_store_creator_factory| for this since it's not necessarily global. |
73 .Create(GithubFileSystem).Create(category='password')) | 73 password_store = ( |
| 74 ObjectStoreCreator.GlobalFactory(ObjectStoreCreator.START_POPULATED) |
| 75 .Create(GithubFileSystem).Create(category='password')) |
74 if USERNAME is None: | 76 if USERNAME is None: |
75 password_data = password_store.GetMulti(('username', 'password')).Get() | 77 password_data = password_store.GetMulti(('username', 'password')).Get() |
76 self._username, self._password = (password_data.get('username'), | 78 self._username, self._password = (password_data.get('username'), |
77 password_data.get('password')) | 79 password_data.get('password')) |
78 else: | 80 else: |
79 password_store.SetMulti({'username': USERNAME, 'password': PASSWORD}) | 81 password_store.SetMulti({'username': USERNAME, 'password': PASSWORD}) |
80 self._username, self._password = (USERNAME, PASSWORD) | 82 self._username, self._password = (USERNAME, PASSWORD) |
81 | 83 |
82 self._fetcher = fetcher | 84 self._fetcher = fetcher |
83 self._blobstore = blobstore | 85 self._blobstore = blobstore |
84 self._stat_object_store = (ObjectStoreCreator.SharedFactory(GetAppVersion()) | 86 self._stat_object_store = ( |
85 .Create(GithubFileSystem).Create()) | 87 object_store_creator_factory.Create(GithubFileSystem).Create()) |
86 self._version = None | 88 self._version = None |
87 self._GetZip(self.Stat(ZIP_KEY).version) | 89 self._GetZip(self.Stat(ZIP_KEY).version) |
88 | 90 |
89 def _GetZip(self, version): | 91 def _GetZip(self, version): |
90 blob = self._blobstore.Get(_MakeBlobstoreKey(version), | 92 blob = self._blobstore.Get(_MakeBlobstoreKey(version), |
91 blobstore.BLOBSTORE_GITHUB) | 93 blobstore.BLOBSTORE_GITHUB) |
92 if blob is not None: | 94 if blob is not None: |
93 try: | 95 try: |
94 self._zip_file = Future(value=ZipFile(StringIO(blob))) | 96 self._zip_file = Future(value=ZipFile(StringIO(blob))) |
95 except BadZipfile as e: | 97 except BadZipfile as e: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 version = (json.loads(result.content).get('commit', {}) | 183 version = (json.loads(result.content).get('commit', {}) |
182 .get('tree', {}) | 184 .get('tree', {}) |
183 .get('sha', None)) | 185 .get('sha', None)) |
184 # Check if the JSON was valid, and set to 0 if not. | 186 # Check if the JSON was valid, and set to 0 if not. |
185 if version is not None: | 187 if version is not None: |
186 self._stat_object_store.Set(path, version) | 188 self._stat_object_store.Set(path, version) |
187 else: | 189 else: |
188 logging.warning('Problem fetching commit hash from github.') | 190 logging.warning('Problem fetching commit hash from github.') |
189 return self._DefaultStat(path) | 191 return self._DefaultStat(path) |
190 return StatInfo(version) | 192 return StatInfo(version) |
OLD | NEW |