| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 raise cherrypy.HTTPRedirect('/admin#tab-packages') | 87 raise cherrypy.HTTPRedirect('/admin#tab-packages') |
| 88 | 88 |
| 89 def _reload_version(self, key): | 89 def _reload_version(self, key): |
| 90 """Reload a single package version from its tarball.""" | 90 """Reload a single package version from its tarball.""" |
| 91 | 91 |
| 92 version = PackageVersion.get(key) | 92 version = PackageVersion.get(key) |
| 93 logging.info('Reloading %s %s' % (version.package.name, version.version)
) | 93 logging.info('Reloading %s %s' % (version.package.name, version.version)
) |
| 94 | 94 |
| 95 with closing(cloud_storage.read(version.storage_path)) as f: | 95 with closing(cloud_storage.read(version.storage_path)) as f: |
| 96 new_version = PackageVersion.from_archive( | 96 new_version = PackageVersion.from_archive( |
| 97 f, uploader=version.uploader) | 97 f, uploaderEmail=version.uploaderEmail) |
| 98 | 98 |
| 99 with models.transaction(): | 99 with models.transaction(): |
| 100 # Reload the old version in case anything (e.g. sort order) changed. | 100 # Reload the old version in case anything (e.g. sort order) changed. |
| 101 version = PackageVersion.get(key) | 101 version = PackageVersion.get(key) |
| 102 package = version.package | 102 package = version.package |
| 103 | 103 |
| 104 # We don't load new_version.package.latest_version here for two | 104 # We don't load new_version.package.latest_version here for two |
| 105 # reasons. One is to avoid a needless data store lookup; the other | 105 # reasons. One is to avoid a needless data store lookup; the other |
| 106 # is because it's possible that that version is being reloaded in | 106 # is because it's possible that that version is being reloaded in |
| 107 # another transaction and thus in a weird transitional state. | 107 # another transaction and thus in a weird transitional state. |
| 108 latest_version_key = Package.latest_version.get_value_for_datastore( | 108 latest_version_key = Package.latest_version.get_value_for_datastore( |
| 109 package) | 109 package) |
| 110 if latest_version_key == key: | 110 if latest_version_key == key: |
| 111 package.latest_version = new_version | 111 package.latest_version = new_version |
| 112 | 112 |
| 113 new_version.created = version.created | 113 new_version.created = version.created |
| 114 new_version.downloads = version.downloads | 114 new_version.downloads = version.downloads |
| 115 new_version.sort_order = version.sort_order | 115 new_version.sort_order = version.sort_order |
| 116 version.delete() | 116 version.delete() |
| 117 new_version.temp_synchronize_uploader_to_uploaderemail_and_pickles() | |
| 118 new_version.put() | 117 new_version.put() |
| 119 | 118 |
| 120 # Only save the package if its latest version has been updated. | 119 # Only save the package if its latest version has been updated. |
| 121 # Otherwise, its latest version may be being updated in parallel, | 120 # Otherwise, its latest version may be being updated in parallel, |
| 122 # causing icky bugs. | 121 # causing icky bugs. |
| 123 if latest_version_key == key: | 122 if latest_version_key == key: |
| 124 package.temp_synchronize_uploader_to_uploaderemail() | |
| 125 package.put() | 123 package.put() |
| 126 package.invalidate_cache() | 124 package.invalidate_cache() |
| 127 | 125 |
| 128 | 126 |
| 129 count = memcache.incr('versions_reloaded') | 127 count = memcache.incr('versions_reloaded') |
| 130 logging.info('%s/%s versions reloaded' % | 128 logging.info('%s/%s versions reloaded' % |
| 131 (count, memcache.get('versions_to_reload'))) | 129 (count, memcache.get('versions_to_reload'))) |
| 132 | 130 |
| 133 @handlers.json_action | 131 @handlers.json_action |
| 134 def reload_status(self, format): | 132 def reload_status(self, format): |
| 135 """Return the status of the current package reload. | 133 """Return the status of the current package reload. |
| 136 | 134 |
| 137 This is a JSON map. If the reload is finished, it will contain only a | 135 This is a JSON map. If the reload is finished, it will contain only a |
| 138 'done' key with value true. If the reload is in progress, it will | 136 'done' key with value true. If the reload is in progress, it will |
| 139 contain 'count' and 'total' keys, indicating the total number of | 137 contain 'count' and 'total' keys, indicating the total number of |
| 140 packages to reload and the number that have been reloaded so far, | 138 packages to reload and the number that have been reloaded so far, |
| 141 respectively. | 139 respectively. |
| 142 """ | 140 """ |
| 143 if not users.is_current_user_admin(): | 141 if not users.is_current_user_admin(): |
| 144 handlers.http_error(403, "Permission denied.") | 142 handlers.http_error(403, "Permission denied.") |
| 145 reload_status = PackageVersion.get_reload_status() | 143 reload_status = PackageVersion.get_reload_status() |
| 146 return json.dumps(reload_status or {'done': True}) | 144 return json.dumps(reload_status or {'done': True}) |
| OLD | NEW |