Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/common/extensions/docs/server2/github_file_system.py

Issue 14218004: Devserver: only populate data during cron jobs, meaning all data from instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix integration test Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/file_system.py ('k') | chrome/common/extensions/docs/server2/github_file_system_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698