OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 from third_party.cloudstorage import cloudstorage_api | 5 from third_party.cloudstorage import cloudstorage_api |
6 from third_party.cloudstorage import common | 6 from third_party.cloudstorage import common |
7 from third_party.cloudstorage import errors | 7 from third_party.cloudstorage import errors |
8 | 8 |
9 from docs_server_utils import StringIdentity | 9 from docs_server_utils import StringIdentity |
10 from file_system import FileSystem, FileNotFoundError, StatInfo | 10 from file_system import FileSystem, FileNotFoundError, StatInfo |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 except errors.Error: | 48 except errors.Error: |
49 raise FileNotFoundError('cloudstorage.listbucket failed for %s: %s' % | 49 raise FileNotFoundError('cloudstorage.listbucket failed for %s: %s' % |
50 (dir_name, traceback.format_exc())) | 50 (dir_name, traceback.format_exc())) |
51 | 51 |
52 def _CreateStatInfo(bucket, path): | 52 def _CreateStatInfo(bucket, path): |
53 full_path = Join(bucket, path) | 53 full_path = Join(bucket, path) |
54 last_commit_file = Join(bucket, LAST_COMMIT_HASH_FILENAME) | 54 last_commit_file = Join(bucket, LAST_COMMIT_HASH_FILENAME) |
55 try: | 55 try: |
56 last_commit = _ReadFile(last_commit_file) | 56 last_commit = _ReadFile(last_commit_file) |
57 if IsDirectory(full_path): | 57 if IsDirectory(full_path): |
58 child_versions = dict((filename, last_commit) | 58 child_versions = dict((filename, last_commit) |
59 for filename in _ListDir(full_path)) | 59 for filename in _ListDir(full_path)) |
60 else: | 60 else: |
61 child_versions = None | 61 child_versions = None |
62 return StatInfo(last_commit, child_versions) | 62 return StatInfo(last_commit, child_versions) |
63 except (TypeError, errors.Error): | 63 except (TypeError, errors.Error): |
64 raise FileNotFoundError('cloudstorage.stat failed for %s: %s' % (path, | 64 raise FileNotFoundError('cloudstorage.stat failed for %s: %s' % (path, |
65 traceback.format_exc())) | 65 traceback.format_exc())) |
66 | 66 |
67 class CloudStorageFileSystem(FileSystem): | 67 class CloudStorageFileSystem(FileSystem): |
68 '''FileSystem implementation which fetches resources from Google Cloud | 68 '''FileSystem implementation which fetches resources from Google Cloud |
69 Storage. | 69 Storage. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 return Future(value=()) | 102 return Future(value=()) |
103 | 103 |
104 def Stat(self, path): | 104 def Stat(self, path): |
105 AssertIsValid(path) | 105 AssertIsValid(path) |
106 try: | 106 try: |
107 return _CreateStatInfo(self._bucket, path) | 107 return _CreateStatInfo(self._bucket, path) |
108 except errors.AuthorizationError: | 108 except errors.AuthorizationError: |
109 self._warnAboutAuthError() | 109 self._warnAboutAuthError() |
110 raise | 110 raise |
111 | 111 |
112 def GetIdentity(self): | 112 def GetStableIdentity(self): |
113 return '@'.join((self.__class__.__name__, StringIdentity(self._bucket))) | 113 return '@'.join((self.__class__.__name__, StringIdentity(self._bucket))) |
114 | 114 |
115 def __repr__(self): | 115 def __repr__(self): |
116 return 'CloudStorageFileSystem(%s)' % self._bucket | 116 return 'CloudStorageFileSystem(%s)' % self._bucket |
117 | 117 |
118 def _warnAboutAuthError(self): | 118 def _warnAboutAuthError(self): |
119 logging.warn(('Authentication error on Cloud Storage. Check if your' | 119 logging.warn(('Authentication error on Cloud Storage. Check if your' |
120 ' appengine project has permissions to Read the GCS' | 120 ' appengine project has permissions to Read the GCS' |
121 ' buckets. If you are running a local appengine server,' | 121 ' buckets. If you are running a local appengine server,' |
122 ' you need to set an access_token in' | 122 ' you need to set an access_token in' |
123 ' local_debug/gcs_debug.conf.' | 123 ' local_debug/gcs_debug.conf.' |
124 ' Remember that this token expires in less than 10' | 124 ' Remember that this token expires in less than 10' |
125 ' minutes, so keep it updated. See' | 125 ' minutes, so keep it updated. See' |
126 ' gcs_file_system_provider.py for instructions.')); | 126 ' gcs_file_system_provider.py for instructions.')); |
127 logging.debug(traceback.format_exc()) | 127 logging.debug(traceback.format_exc()) |
OLD | NEW |