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

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

Issue 15009006: Docserver: refactor Servlet, ObjectStore, and ServerInstance architecture to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cduvall, redirect fix Created 7 years, 7 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 from StringIO import StringIO
8 9
9 import appengine_blobstore as blobstore 10 import appengine_blobstore as blobstore
11 from appengine_url_fetcher import AppEngineUrlFetcher
10 from appengine_wrappers import GetAppVersion, urlfetch 12 from appengine_wrappers import GetAppVersion, urlfetch
11 from file_system import FileSystem, StatInfo 13 from file_system import FileSystem, StatInfo
12 from future import Future 14 from future import Future
13 from object_store_creator import ObjectStoreCreator 15 from object_store_creator import ObjectStoreCreator
14 from StringIO import StringIO 16 import url_constants
15 from zipfile import ZipFile, BadZipfile 17 from zipfile import ZipFile, BadZipfile
16 18
17 ZIP_KEY = 'zipball' 19 ZIP_KEY = 'zipball'
18 USERNAME = None 20 USERNAME = None
19 PASSWORD = None 21 PASSWORD = None
20 22
21 def _MakeBlobstoreKey(version): 23 def _MakeBlobstoreKey(version):
22 return ZIP_KEY + '.' + str(version) 24 return ZIP_KEY + '.' + str(version)
23 25
24 class _AsyncFetchFutureZip(object): 26 class _AsyncFetchFutureZip(object):
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 except BadZipfile as e: 60 except BadZipfile as e:
59 logging.error('Bad github zip file: %s' % e) 61 logging.error('Bad github zip file: %s' % e)
60 return None 62 return None
61 63
62 self._blobstore.Set(_MakeBlobstoreKey(self._key_to_set), 64 self._blobstore.Set(_MakeBlobstoreKey(self._key_to_set),
63 blob, 65 blob,
64 blobstore.BLOBSTORE_GITHUB) 66 blobstore.BLOBSTORE_GITHUB)
65 return return_zip 67 return return_zip
66 68
67 class GithubFileSystem(FileSystem): 69 class GithubFileSystem(FileSystem):
68 """FileSystem implementation which fetches resources from github. 70 @staticmethod
69 """ 71 def Create(object_store_creator):
70 def __init__(self, fetcher, blobstore): 72 return GithubFileSystem(
71 # The password store is the same for all branches and versions. 73 AppEngineUrlFetcher(url_constants.GITHUB_URL),
72 password_store = (ObjectStoreCreator.GlobalFactory() 74 blobstore.AppEngineBlobstore(),
73 .Create(GithubFileSystem).Create(category='password')) 75 object_store_creator)
76
77 def __init__(self, fetcher, blobstore, object_store_creator):
78 # Password store doesn't depend on channel, and if we don't cancel the app
79 # version then the whole advantage of having it in the first place is
80 # greatly lessened (likewise it should always start populated).
81 password_store = object_store_creator.Create(
82 GithubFileSystem,
83 channel=None,
84 app_version=None,
85 category='password',
86 start_empty=False)
74 if USERNAME is None: 87 if USERNAME is None:
75 password_data = password_store.GetMulti(('username', 'password')).Get() 88 password_data = password_store.GetMulti(('username', 'password')).Get()
76 self._username, self._password = (password_data.get('username'), 89 self._username, self._password = (password_data.get('username'),
77 password_data.get('password')) 90 password_data.get('password'))
78 else: 91 else:
79 password_store.SetMulti({'username': USERNAME, 'password': PASSWORD}) 92 password_store.SetMulti({'username': USERNAME, 'password': PASSWORD})
80 self._username, self._password = (USERNAME, PASSWORD) 93 self._username, self._password = (USERNAME, PASSWORD)
81 94
82 self._fetcher = fetcher 95 self._fetcher = fetcher
83 self._blobstore = blobstore 96 self._blobstore = blobstore
84 self._stat_object_store = (ObjectStoreCreator.SharedFactory(GetAppVersion()) 97 # Github has no knowledge of Chrome channels, set channel to None.
85 .Create(GithubFileSystem).Create()) 98 self._stat_object_store = object_store_creator.Create(
99 GithubFileSystem,
100 channel=None)
86 self._version = None 101 self._version = None
87 self._GetZip(self.Stat(ZIP_KEY).version) 102 self._GetZip(self.Stat(ZIP_KEY).version)
88 103
89 def _GetZip(self, version): 104 def _GetZip(self, version):
90 blob = self._blobstore.Get(_MakeBlobstoreKey(version), 105 blob = self._blobstore.Get(_MakeBlobstoreKey(version),
91 blobstore.BLOBSTORE_GITHUB) 106 blobstore.BLOBSTORE_GITHUB)
92 if blob is not None: 107 if blob is not None:
93 try: 108 try:
94 self._zip_file = Future(value=ZipFile(StringIO(blob))) 109 self._zip_file = Future(value=ZipFile(StringIO(blob)))
95 except BadZipfile as e: 110 except BadZipfile as e:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 version = (json.loads(result.content).get('commit', {}) 196 version = (json.loads(result.content).get('commit', {})
182 .get('tree', {}) 197 .get('tree', {})
183 .get('sha', None)) 198 .get('sha', None))
184 # Check if the JSON was valid, and set to 0 if not. 199 # Check if the JSON was valid, and set to 0 if not.
185 if version is not None: 200 if version is not None:
186 self._stat_object_store.Set(path, version) 201 self._stat_object_store.Set(path, version)
187 else: 202 else:
188 logging.warning('Problem fetching commit hash from github.') 203 logging.warning('Problem fetching commit hash from github.')
189 return self._DefaultStat(path) 204 return self._DefaultStat(path)
190 return StatInfo(version) 205 return StatInfo(version)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698