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 21 matching lines...) Expand all Loading... | |
32 try: | 32 try: |
33 with cloudstorage_api.open('/' + filename, 'r') as f: | 33 with cloudstorage_api.open('/' + filename, 'r') as f: |
34 return f.read() | 34 return f.read() |
35 except errors.Error: | 35 except errors.Error: |
36 raise FileNotFoundError('Read failed for %s: %s' % (filename, | 36 raise FileNotFoundError('Read failed for %s: %s' % (filename, |
37 traceback.format_exc())) | 37 traceback.format_exc())) |
38 | 38 |
39 def _ListDir(dir_name): | 39 def _ListDir(dir_name): |
40 AssertIsDirectory(dir_name) | 40 AssertIsDirectory(dir_name) |
41 try: | 41 try: |
42 files = cloudstorage_api.listbucket('/' + dir_name) | 42 files = cloudstorage_api.listbucket('/' + dir_name, delimiter='/') |
43 return [os_path.filename.lstrip('/') for os_path in files] | 43 return [os_path.filename.lstrip('/')[len(dir_name):] for os_path in files] |
44 except errors.Error: | 44 except errors.Error: |
45 raise FileNotFoundError('cloudstorage.listbucket failed for %s: %s' % | 45 raise FileNotFoundError('cloudstorage.listbucket failed for %s: %s' % |
46 (dir_name, traceback.format_exc())) | 46 (dir_name, traceback.format_exc())) |
47 | 47 |
48 def _CreateStatInfo(bucket, path): | 48 def _CreateStatInfo(bucket, path): |
49 full_path = Join(bucket, path) | 49 full_path = Join(bucket, path) |
50 last_commit_file = Join(bucket, LAST_COMMIT_HASH_FILENAME) | 50 last_commit_file = Join(bucket, LAST_COMMIT_HASH_FILENAME) |
51 try: | 51 try: |
52 last_commit = _ReadFile(last_commit_file) | 52 last_commit = _ReadFile(last_commit_file) |
53 if IsDirectory(full_path): | 53 if IsDirectory(full_path): |
54 child_versions = dict() | 54 child_versions = dict() |
55 # Fetching stats for all files under full_path, recursively. The | 55 # Fetching stats for all files under full_path, recursively. The |
56 # listbucket method uses a prefix approach to simulate hierarchy, | 56 # listbucket method uses a prefix approach to simulate hierarchy, |
57 # but calling it without the "delimiter" argument searches for prefix, | 57 # but calling it without the "delimiter" argument searches for prefix, |
58 # which means, for directories, everything beneath it. | 58 # which means, for directories, everything beneath it. |
59 for _file in cloudstorage_api.listbucket('/' + full_path): | 59 for _file in cloudstorage_api.listbucket('/' + full_path): |
not at google - send to devlin
2014/02/14 23:03:55
p.s. why doesn't this use ListDir(..)?
Renato Mangini (chromium)
2014/02/15 02:01:52
Old code, didn't go through it. Fixing now, thanks
| |
60 filename = _file.filename.lstrip('/')[len(full_path):] | 60 filename = _file.filename.lstrip('/')[len(full_path):] |
61 child_versions[filename] = last_commit | 61 child_versions[filename] = last_commit |
62 else: | 62 else: |
63 child_versions = None | 63 child_versions = None |
64 return StatInfo(last_commit, child_versions) | 64 return StatInfo(last_commit, child_versions) |
65 except (TypeError, errors.Error): | 65 except (TypeError, errors.Error): |
66 raise FileNotFoundError('cloudstorage.stat failed for %s: %s' % (path, | 66 raise FileNotFoundError('cloudstorage.stat failed for %s: %s' % (path, |
67 traceback.format_exc())) | 67 traceback.format_exc())) |
68 | 68 |
69 class CloudStorageFileSystem(FileSystem): | 69 class CloudStorageFileSystem(FileSystem): |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 def _warnAboutAuthError(self): | 120 def _warnAboutAuthError(self): |
121 logging.warn(('Authentication error on Cloud Storage. Check if your' | 121 logging.warn(('Authentication error on Cloud Storage. Check if your' |
122 ' appengine project has permissions to Read the GCS' | 122 ' appengine project has permissions to Read the GCS' |
123 ' buckets. If you are running a local appengine server,' | 123 ' buckets. If you are running a local appengine server,' |
124 ' you need to set an access_token in' | 124 ' you need to set an access_token in' |
125 ' local_debug/gcs_debug.conf.' | 125 ' local_debug/gcs_debug.conf.' |
126 ' Remember that this token expires in less than 10' | 126 ' Remember that this token expires in less than 10' |
127 ' minutes, so keep it updated. See' | 127 ' minutes, so keep it updated. See' |
128 ' gcs_file_system_provider.py for instructions.')); | 128 ' gcs_file_system_provider.py for instructions.')); |
129 logging.debug(traceback.format_exc()) | 129 logging.debug(traceback.format_exc()) |
OLD | NEW |