Ejemplo n.º 1
0
    def _reload_version(self, key):
        """Reload a single package version from its tarball."""

        version = PackageVersion.get(key)
        with closing(cloud_storage.read(version.storage_path)) as f:
            new_version = PackageVersion.from_archive(
                f, uploader=version.uploader)

        with models.transaction():
            # Reload the old version in case anything (e.g. sort order) changed.
            version = PackageVersion.get(key)
            package = version.package

            # We don't load new_version.package.latest_version here for two
            # reasons. One is to avoid a needless data store lookup; the other
            # is because it's possible that that version is being reloaded in
            # another transaction and thus in a weird transitional state.
            latest_version_key = Package.latest_version.get_value_for_datastore(
                package)
            if latest_version_key == key:
                package.latest_version = new_version

            new_version.created = version.created
            new_version.downloads = version.downloads
            new_version.sort_order = version.sort_order
            version.delete()
            new_version.put()
            package.put()

        memcache.incr('versions_reloaded')
Ejemplo n.º 2
0
 def _count_download(self, key):
     """Increment the download count for a package version."""
     with models.transaction():
         version = PackageVersion.get(key)
         version.downloads += 1
         version.package.downloads += 1
         version.put()
         version.package.put()
Ejemplo n.º 3
0
 def _count_download(self, key):
     """Increment the download count for a package version."""
     with models.transaction():
         version = PackageVersion.get(key)
         version.downloads += 1
         version.package.downloads += 1
         version.put()
         version.package.put()
Ejemplo n.º 4
0
    def _reload_version(self, key):
        """Reload a single package version from its tarball."""

        version = PackageVersion.get(key)
        logging.info('Reloading %s %s' %
                     (version.package.name, version.version))

        with closing(cloud_storage.read(version.storage_path)) as f:
            new_version = PackageVersion.from_archive(
                f, uploaderEmail=version.uploaderEmail)

        with models.transaction():
            # Reload the old version in case anything (e.g. sort order) changed.
            version = PackageVersion.get(key)
            package = version.package

            # We don't load new_version.package.latest_version here for two
            # reasons. One is to avoid a needless data store lookup; the other
            # is because it's possible that that version is being reloaded in
            # another transaction and thus in a weird transitional state.
            latest_version_key = Package.latest_version.get_value_for_datastore(
                package)
            if latest_version_key == key:
                package.latest_version = new_version

            new_version.created = version.created
            new_version.downloads = version.downloads
            new_version.sort_order = version.sort_order
            version.delete()
            new_version.put()

            # Only save the package if its latest version has been updated.
            # Otherwise, its latest version may be being updated in parallel,
            # causing icky bugs.
            if latest_version_key == key:
                package.put()
                package.invalidate_cache()

        count = memcache.incr('versions_reloaded')
        logging.info('%s/%s versions reloaded' %
                     (count, memcache.get('versions_to_reload')))
Ejemplo n.º 5
0
    def _reload_version(self, key):
        """Reload a single package version from its tarball."""

        version = PackageVersion.get(key)
        logging.info('Reloading %s %s' % (version.package.name, version.version))

        with closing(cloud_storage.read(version.storage_path)) as f:
            new_version = PackageVersion.from_archive(
                f, uploader=version.uploader)

        with models.transaction():
            # Reload the old version in case anything (e.g. sort order) changed.
            version = PackageVersion.get(key)
            package = version.package

            # We don't load new_version.package.latest_version here for two
            # reasons. One is to avoid a needless data store lookup; the other
            # is because it's possible that that version is being reloaded in
            # another transaction and thus in a weird transitional state.
            latest_version_key = Package.latest_version.get_value_for_datastore(
                package)
            if latest_version_key == key:
                package.latest_version = new_version

            new_version.created = version.created
            new_version.downloads = version.downloads
            new_version.sort_order = version.sort_order
            version.delete()
            new_version.put()

            # Only save the package if its latest version has been updated.
            # Otherwise, its latest version may be being updated in parallel,
            # causing icky bugs.
            if latest_version_key == key:
                package.put()
                package.invalidate_cache()


        count = memcache.incr('versions_reloaded')
        logging.info('%s/%s versions reloaded' %
                     (count, memcache.get('versions_to_reload')))