OLD | NEW |
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 from cStringIO import StringIO | 5 from cStringIO import StringIO |
6 from contextlib import closing | 6 from contextlib import closing |
7 from uuid import uuid4 | 7 from uuid import uuid4 |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import time | 10 import time |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 id: The id of the package in cloud storage. | 72 id: The id of the package in cloud storage. |
73 """ | 73 """ |
74 | 74 |
75 try: | 75 try: |
76 route = handlers.request().route | 76 route = handlers.request().route |
77 if 'id' in route: del route['id'] | 77 if 'id' in route: del route['id'] |
78 | 78 |
79 try: | 79 try: |
80 with closing(cloud_storage.read('tmp/' + id)) as f: | 80 with closing(cloud_storage.read('tmp/' + id)) as f: |
81 version = PackageVersion.from_archive( | 81 version = PackageVersion.from_archive( |
82 f, uploader=handlers.get_oauth_user()) | 82 f, uploaderEmail=handlers.get_oauth_user().email()) |
83 except (KeyError, files.ExistenceError): | 83 except (KeyError, files.ExistenceError): |
84 handlers.http_error( | 84 handlers.http_error( |
85 403, "Package upload " + id + " does not exist.") | 85 403, "Package upload " + id + " does not exist.") |
86 | 86 |
87 # If the package for this version already exists, make sure we're an | 87 # If the package for this version already exists, make sure we're an |
88 # uploader for it. If it doesn't, we're fine to create it anew. | 88 # uploader for it. If it doesn't, we're fine to create it anew. |
89 if version.package.is_saved(): | 89 if version.package.is_saved(): |
90 if not version.package.has_uploader(handlers.get_oauth_user()): | 90 if not version.package.has_uploader_email( |
| 91 handlers.get_oauth_user().email()): |
91 handlers.http_error( | 92 handlers.http_error( |
92 403, "You aren't an uploader for package '%s'." % | 93 403, "You aren't an uploader for package '%s'." % |
93 version.package.name) | 94 version.package.name) |
94 elif version.package.has_version(version.version): | 95 elif version.package.has_version(version.version): |
95 message = 'Package "%s" already has version "%s".' % \ | 96 message = 'Package "%s" already has version "%s".' % \ |
96 (version.package.name, version.version) | 97 (version.package.name, version.version) |
97 handlers.http_error(400, message) | 98 handlers.http_error(400, message) |
98 | 99 |
99 if self._should_update_latest_version(version): | 100 if self._should_update_latest_version(version): |
100 version.package.latest_version = version | 101 version.package.latest_version = version |
101 else: | 102 else: |
102 version.package.latest_version = version | 103 version.package.latest_version = version |
103 | 104 |
104 cloud_storage.modify_object(version.storage_path, | 105 cloud_storage.modify_object(version.storage_path, |
105 acl='public-read', | 106 acl='public-read', |
106 copy_source='tmp/' + id) | 107 copy_source='tmp/' + id) |
107 | 108 |
108 with models.transaction(): | 109 with models.transaction(): |
109 version.package.temp_synchronize_uploaders_to_uploaderemails() | |
110 version.package.put() | 110 version.package.put() |
111 version.temp_synchronize_uploader_to_uploaderemail_and_pickles() | |
112 version.put() | 111 version.put() |
113 version.package.invalidate_cache() | 112 version.package.invalidate_cache() |
114 | 113 |
115 deferred.defer(self._compute_version_order, version.package.name) | 114 deferred.defer(self._compute_version_order, version.package.name) |
116 | 115 |
117 return handlers.json_success('%s %s uploaded successfully.' % | 116 return handlers.json_success('%s %s uploaded successfully.' % |
118 (version.package.name, version.version)) | 117 (version.package.name, version.version)) |
119 finally: | 118 finally: |
120 cloud_storage.delete_object('tmp/' + id) | 119 cloud_storage.delete_object('tmp/' + id) |
121 | 120 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 @handlers.requires_oauth_key | 180 @handlers.requires_oauth_key |
182 @handlers.requires_uploader | 181 @handlers.requires_uploader |
183 def new_dartdoc(self, package_id, id): | 182 def new_dartdoc(self, package_id, id): |
184 """Retrieve the form for uploading dartdoc for this package version.""" | 183 """Retrieve the form for uploading dartdoc for this package version.""" |
185 version = handlers.request().package_version(id) | 184 version = handlers.request().package_version(id) |
186 upload = cloud_storage.Upload(version.dartdoc_storage_path, | 185 upload = cloud_storage.Upload(version.dartdoc_storage_path, |
187 acl='public-read', | 186 acl='public-read', |
188 size_range=(0, Package.MAX_SIZE)) | 187 size_range=(0, Package.MAX_SIZE)) |
189 | 188 |
190 return upload.to_json() | 189 return upload.to_json() |
OLD | NEW |