Esempio n. 1
0
def _check_image_used(legacy_image_id):
  assert legacy_image_id is not None

  with db_transaction():
    # Check if the image is referenced by a manifest.
    try:
      ManifestLegacyImage.select().where(ManifestLegacyImage.image == legacy_image_id).get()
      return True
    except ManifestLegacyImage.DoesNotExist:
      pass

    # Check if the image is referenced by a tag.
    try:
      RepositoryTag.select().where(RepositoryTag.image == legacy_image_id).get()
      return True
    except RepositoryTag.DoesNotExist:
      pass

    # Check if the image is referenced by another image.
    try:
      Image.select().where(Image.parent == legacy_image_id).get()
      return True
    except Image.DoesNotExist:
      pass

  return False
Esempio n. 2
0
File: shared.py Progetto: zhill/quay
def get_manifest_for_legacy_image(image_id):
    """ Returns a manifest that is associated with the given image, if any, or None if none. """
    try:
        query = (ManifestLegacyImage.select(
            ManifestLegacyImage, Manifest).join(Manifest).where(
                ManifestLegacyImage.image == image_id))
        return query.get().manifest
    except ManifestLegacyImage.DoesNotExist:
        return None
Esempio n. 3
0
File: shared.py Progetto: zhill/quay
def get_legacy_image_for_manifest(manifest_id):
    """ Returns the legacy image associated with the given manifest, if any, or None if none. """
    try:
        query = (ManifestLegacyImage.select(
            ManifestLegacyImage, Image).join(Image).where(
                ManifestLegacyImage.manifest == manifest_id))
        return query.get().image
    except ManifestLegacyImage.DoesNotExist:
        return None
Esempio n. 4
0
File: tag.py Progetto: xzwupeng/quay
def get_legacy_images_for_tags(tags):
    """ Returns a map from tag ID to the legacy image for the tag. """
    if not tags:
        return {}

    query = (ManifestLegacyImage.select(
        ManifestLegacyImage, Image,
        ImageStorage).join(Image).join(ImageStorage).where(
            ManifestLegacyImage.manifest << [tag.manifest_id for tag in tags]))

    by_manifest = {mli.manifest_id: mli.image for mli in query}
    return {
        tag.id: by_manifest[tag.manifest_id]
        for tag in tags if tag.manifest_id in by_manifest
    }