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 from StringIO import StringIO | 8 from StringIO import StringIO |
9 | 9 |
10 import appengine_blobstore as blobstore | 10 import appengine_blobstore as blobstore |
11 from appengine_url_fetcher import AppEngineUrlFetcher | 11 from appengine_url_fetcher import AppEngineUrlFetcher |
12 from appengine_wrappers import GetAppVersion, urlfetch | 12 from appengine_wrappers import GetAppVersion, urlfetch |
| 13 from docs_server_utils import StringIdentity |
13 from file_system import FileSystem, StatInfo | 14 from file_system import FileSystem, StatInfo |
14 from future import Future | 15 from future import Future |
15 from object_store_creator import ObjectStoreCreator | 16 from object_store_creator import ObjectStoreCreator |
16 import url_constants | 17 import url_constants |
17 from zipfile import ZipFile, BadZipfile | 18 from zipfile import ZipFile, BadZipfile |
18 | 19 |
19 ZIP_KEY = 'zipball' | 20 ZIP_KEY = 'zipball' |
20 USERNAME = None | 21 USERNAME = None |
21 PASSWORD = None | 22 PASSWORD = None |
22 | 23 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 64 |
64 self._blobstore.Set(_MakeBlobstoreKey(self._key_to_set), | 65 self._blobstore.Set(_MakeBlobstoreKey(self._key_to_set), |
65 blob, | 66 blob, |
66 blobstore.BLOBSTORE_GITHUB) | 67 blobstore.BLOBSTORE_GITHUB) |
67 return return_zip | 68 return return_zip |
68 | 69 |
69 class GithubFileSystem(FileSystem): | 70 class GithubFileSystem(FileSystem): |
70 @staticmethod | 71 @staticmethod |
71 def Create(object_store_creator): | 72 def Create(object_store_creator): |
72 return GithubFileSystem( | 73 return GithubFileSystem( |
73 AppEngineUrlFetcher(url_constants.GITHUB_URL), | 74 url_constants.GITHUB_URL, |
74 blobstore.AppEngineBlobstore(), | 75 blobstore.AppEngineBlobstore(), |
75 object_store_creator) | 76 object_store_creator) |
76 | 77 |
77 def __init__(self, fetcher, blobstore, object_store_creator): | 78 def __init__(self, url, blobstore, object_store_creator): |
78 # Password store doesn't depend on channel, and if we don't cancel the app | 79 # If we key the password store on the app version then the whole advantage |
79 # version then the whole advantage of having it in the first place is | 80 # of having it in the first place is greatly lessened (likewise it should |
80 # greatly lessened (likewise it should always start populated). | 81 # always start populated). |
81 password_store = object_store_creator.Create( | 82 password_store = object_store_creator.Create( |
82 GithubFileSystem, | 83 GithubFileSystem, |
83 channel=None, | |
84 app_version=None, | 84 app_version=None, |
85 category='password', | 85 category='password', |
86 start_empty=False) | 86 start_empty=False) |
87 if USERNAME is None: | 87 if USERNAME is None: |
88 password_data = password_store.GetMulti(('username', 'password')).Get() | 88 password_data = password_store.GetMulti(('username', 'password')).Get() |
89 self._username, self._password = (password_data.get('username'), | 89 self._username, self._password = (password_data.get('username'), |
90 password_data.get('password')) | 90 password_data.get('password')) |
91 else: | 91 else: |
92 password_store.SetMulti({'username': USERNAME, 'password': PASSWORD}) | 92 password_store.SetMulti({'username': USERNAME, 'password': PASSWORD}) |
93 self._username, self._password = (USERNAME, PASSWORD) | 93 self._username, self._password = (USERNAME, PASSWORD) |
94 | 94 |
95 self._fetcher = fetcher | 95 self._url = url |
| 96 self._fetcher = AppEngineUrlFetcher(url) |
96 self._blobstore = blobstore | 97 self._blobstore = blobstore |
97 # Github has no knowledge of Chrome channels, set channel to None. | 98 self._stat_object_store = object_store_creator.Create(GithubFileSystem) |
98 self._stat_object_store = object_store_creator.Create( | |
99 GithubFileSystem, | |
100 channel=None) | |
101 self._version = None | 99 self._version = None |
102 self._GetZip(self.Stat(ZIP_KEY).version) | 100 self._GetZip(self.Stat(ZIP_KEY).version) |
103 | 101 |
104 def _GetZip(self, version): | 102 def _GetZip(self, version): |
105 blob = self._blobstore.Get(_MakeBlobstoreKey(version), | 103 blob = self._blobstore.Get(_MakeBlobstoreKey(version), |
106 blobstore.BLOBSTORE_GITHUB) | 104 blobstore.BLOBSTORE_GITHUB) |
107 if blob is not None: | 105 if blob is not None: |
108 try: | 106 try: |
109 self._zip_file = Future(value=ZipFile(StringIO(blob))) | 107 self._zip_file = Future(value=ZipFile(StringIO(blob))) |
110 except BadZipfile as e: | 108 except BadZipfile as e: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 version = (json.loads(result.content).get('commit', {}) | 194 version = (json.loads(result.content).get('commit', {}) |
197 .get('tree', {}) | 195 .get('tree', {}) |
198 .get('sha', None)) | 196 .get('sha', None)) |
199 # Check if the JSON was valid, and set to 0 if not. | 197 # Check if the JSON was valid, and set to 0 if not. |
200 if version is not None: | 198 if version is not None: |
201 self._stat_object_store.Set(path, version) | 199 self._stat_object_store.Set(path, version) |
202 else: | 200 else: |
203 logging.warning('Problem fetching commit hash from github.') | 201 logging.warning('Problem fetching commit hash from github.') |
204 return self._DefaultStat(path) | 202 return self._DefaultStat(path) |
205 return StatInfo(version) | 203 return StatInfo(version) |
| 204 |
| 205 def GetIdentity(self): |
| 206 return '%s@%s' % (self.__class__.__name__, StringIdentity(self._url)) |
OLD | NEW |