OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 os | 5 import os |
6 import re | 6 import re |
7 import sys | 7 import sys |
8 | 8 |
9 | 9 |
10 def LoadSupport(input_api): | 10 def LoadSupport(input_api): |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if not os.path.exists(file_path): | 73 if not os.path.exists(file_path): |
74 results.append(output_api.PresubmitError( | 74 results.append(output_api.PresubmitError( |
75 'Hash file exists, but file not found: %s' % hash_path)) | 75 'Hash file exists, but file not found: %s' % hash_path)) |
76 continue | 76 continue |
77 if cloud_storage.GetHash(file_path) != file_hash: | 77 if cloud_storage.GetHash(file_path) != file_hash: |
78 results.append(output_api.PresubmitError( | 78 results.append(output_api.PresubmitError( |
79 'Hash file does not match file\'s actual hash: %s' % hash_path)) | 79 'Hash file does not match file\'s actual hash: %s' % hash_path)) |
80 continue | 80 continue |
81 | 81 |
82 try: | 82 try: |
83 bucket_input = raw_input('Uploading to Cloud Storage: %s\nIs this file ' | 83 bucket_input = raw_input('Uploading to Cloud Storage: %s\n' |
84 '[p]ublic or Google-[i]nternal?').lower() | 84 'Is this file [p]ublic or Google-[i]nternal?' |
| 85 % file_path).lower() |
85 if 'public'.startswith(bucket_input): | 86 if 'public'.startswith(bucket_input): |
86 bucket = cloud_storage.PUBLIC_BUCKET | 87 bucket = cloud_storage.PUBLIC_BUCKET |
87 elif ('internal'.startswith(bucket_input) or | 88 elif ('internal'.startswith(bucket_input) or |
88 'google-internal'.startswith(bucket_input)): | 89 'google-internal'.startswith(bucket_input)): |
89 bucket = cloud_storage.INTERNAL_BUCKET | 90 bucket = cloud_storage.INTERNAL_BUCKET |
90 else: | 91 else: |
91 results.append(output_api.PresubmitError( | 92 results.append(output_api.PresubmitError( |
92 'Response was neither "public" nor "internal": %s' % bucket_input)) | 93 'Response was neither "public" nor "internal": %s' % bucket_input)) |
93 return results | 94 return results |
94 | 95 |
95 cloud_storage.Insert(bucket, file_hash, file_path) | 96 cloud_storage.Insert(bucket, file_hash, file_path) |
96 results.append(output_api.PresubmitNotifyResult( | 97 results.append(output_api.PresubmitNotifyResult( |
97 'Uploaded file to Cloud Storage: %s' % hash_path)) | 98 'Uploaded file to Cloud Storage: %s' % file_path)) |
98 except cloud_storage.CloudStorageError, e: | 99 except cloud_storage.CloudStorageError, e: |
99 results.append(output_api.PresubmitError( | 100 results.append(output_api.PresubmitError( |
100 'Unable to upload to Cloud Storage: %s\n\n%s' % (hash_path, e))) | 101 'Unable to upload to Cloud Storage: %s\n\n%s' % (file_path, e))) |
101 | 102 |
102 return results | 103 return results |
103 | 104 |
104 | 105 |
105 def _VerifyFilesInCloud(input_api, output_api): | 106 def _VerifyFilesInCloud(input_api, output_api): |
106 """Searches for .sha1 files and uploads them to Cloud Storage. | 107 """Searches for .sha1 files and uploads them to Cloud Storage. |
107 | 108 |
108 It validates all the hashes and skips upload if not necessary. | 109 It validates all the hashes and skips upload if not necessary. |
109 """ | 110 """ |
110 results = [] | 111 results = [] |
111 for hash_path, _ in _GetFilesNotInCloud(input_api): | 112 for hash_path, _ in _GetFilesNotInCloud(input_api): |
112 results.append(output_api.PresubmitError( | 113 results.append(output_api.PresubmitError( |
113 'Attemping to commit hash file, but corresponding ' | 114 'Attemping to commit hash file, but corresponding ' |
114 'data file is not in Cloud Storage: %s' % hash_path)) | 115 'data file is not in Cloud Storage: %s' % hash_path)) |
115 return results | 116 return results |
116 | 117 |
117 | 118 |
118 def CheckChangeOnUpload(input_api, output_api): | 119 def CheckChangeOnUpload(input_api, output_api): |
119 return _SyncFilesToCloud(input_api, output_api) | 120 return _SyncFilesToCloud(input_api, output_api) |
120 | 121 |
121 | 122 |
122 def CheckChangeOnCommit(input_api, output_api): | 123 def CheckChangeOnCommit(input_api, output_api): |
123 return _VerifyFilesInCloud(input_api, output_api) | 124 return _VerifyFilesInCloud(input_api, output_api) |
OLD | NEW |