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 urlfetch | 10 from appengine_wrappers import urlfetch |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 result = {} | 124 result = {} |
125 for path in paths: | 125 for path in paths: |
126 if path.endswith('/'): | 126 if path.endswith('/'): |
127 result[path] = self._ListDir(path) | 127 result[path] = self._ListDir(path) |
128 else: | 128 else: |
129 result[path] = self._ReadFile(path) | 129 result[path] = self._ReadFile(path) |
130 return Future(value=result) | 130 return Future(value=result) |
131 | 131 |
132 def _DefaultStat(self, path): | 132 def _DefaultStat(self, path): |
133 version = 0 | 133 version = 0 |
134 # Cache for a minute so we don't try to keep fetching bad data. | 134 # TODO(kalman): we should replace all of this by wrapping the |
135 self._stat_object_store.Set(path, version, time=60) | 135 # GithubFileSystem in a CachingFileSystem. A lot of work has been put into |
| 136 # CFS to be robust, and GFS is missing out. |
| 137 # For example: the following line is wrong, but it could be moot. |
| 138 self._stat_object_store.Set(path, version) |
136 return StatInfo(version) | 139 return StatInfo(version) |
137 | 140 |
138 def Stat(self, path): | 141 def Stat(self, path): |
139 version = self._stat_object_store.Get(path).Get() | 142 version = self._stat_object_store.Get(path).Get() |
140 if version is not None: | 143 if version is not None: |
141 return StatInfo(version) | 144 return StatInfo(version) |
142 try: | 145 try: |
143 result = self._fetcher.Fetch('commits/HEAD', | 146 result = self._fetcher.Fetch('commits/HEAD', |
144 username=USERNAME, | 147 username=USERNAME, |
145 password=PASSWORD) | 148 password=PASSWORD) |
(...skipping 12 matching lines...) Expand all Loading... |
158 version = (json.loads(result.content).get('commit', {}) | 161 version = (json.loads(result.content).get('commit', {}) |
159 .get('tree', {}) | 162 .get('tree', {}) |
160 .get('sha', None)) | 163 .get('sha', None)) |
161 # Check if the JSON was valid, and set to 0 if not. | 164 # Check if the JSON was valid, and set to 0 if not. |
162 if version is not None: | 165 if version is not None: |
163 self._stat_object_store.Set(path, version) | 166 self._stat_object_store.Set(path, version) |
164 else: | 167 else: |
165 logging.warning('Problem fetching commit hash from github.') | 168 logging.warning('Problem fetching commit hash from github.') |
166 return self._DefaultStat(path) | 169 return self._DefaultStat(path) |
167 return StatInfo(version) | 170 return StatInfo(version) |
OLD | NEW |