[ARVADOS] updated: 80ed3a2494a460c7efa612f5d5d310ff5f6fa164
git at public.curoverse.com
git at public.curoverse.com
Thu Jun 12 15:35:29 EDT 2014
Summary of changes:
sdk/python/arvados/commands/keepdocker.py | 39 +++++++++++++++++++------------
1 file changed, 24 insertions(+), 15 deletions(-)
via 80ed3a2494a460c7efa612f5d5d310ff5f6fa164 (commit)
from aba01982549102659a7c49a3241544c9f27892b9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 80ed3a2494a460c7efa612f5d5d310ff5f6fa164
Author: Brett Smith <brett at curoverse.com>
Date: Thu Jun 12 15:36:18 2014 -0400
2879: arv-keepdocker reports a better error for ambiguous hashes.
Refs #2879.
diff --git a/sdk/python/arvados/commands/keepdocker.py b/sdk/python/arvados/commands/keepdocker.py
index c04885c..abf60f2 100644
--- a/sdk/python/arvados/commands/keepdocker.py
+++ b/sdk/python/arvados/commands/keepdocker.py
@@ -82,23 +82,31 @@ def docker_images():
list_proc.stdout.close()
check_docker(list_proc, "images")
-def find_image_hash(image_search, image_tag=None):
- # Given one argument, search for one Docker image with a matching hash,
- # and return its full hash.
- # Given two arguments, also search for a Docker image with the same
- # repository and tag. If one is found, return its hash; otherwise,
- # fall back to the one-argument hash search.
+def find_image_hashes(image_search, image_tag=None):
+ # Given one argument, search for Docker images with matching hashes,
+ # and return their full hashes in a set.
+ # Given two arguments, also search for a Docker image with the
+ # same repository and tag. If one is found, return its hash in a
+ # set; otherwise, fall back to the one-argument hash search.
# Returns None if no match is found, or a hash search is ambiguous.
hash_search = image_search.lower()
hash_matches = set()
for image in docker_images():
if (image.repo == image_search) and (image.tag == image_tag):
- return image.hash
+ return set([image.hash])
elif image.hash.startswith(hash_search):
hash_matches.add(image.hash)
- if len(hash_matches) == 1:
- return hash_matches.pop()
- return None
+ return hash_matches
+
+def find_one_image_hash(image_search, image_tag=None):
+ hashes = find_image_hashes(image_search, image_tag)
+ hash_count = len(hashes)
+ if hash_count == 1:
+ return hashes.pop()
+ elif hash_count == 0:
+ raise DockerError("no matching image found")
+ else:
+ raise DockerError("{} images match {}".format(hash_count, image_search))
def stat_cache_name(image_file):
return getattr(image_file, 'name', image_file) + '.stat'
@@ -149,14 +157,15 @@ def main(arguments=None):
# Pull the image if requested, unless the image is specified as a hash
# that we already have.
- if args.pull and (find_image_hash(args.image) is None):
+ if args.pull and not find_image_hashes(args.image):
pull_image(args.image, args.tag)
- image_hash = find_image_hash(args.image, args.tag)
- if image_hash is None:
- print >>sys.stderr, "arv-keepdocker: No image found."
+ try:
+ image_hash = find_one_image_hash(args.image, args.tag)
+ except DockerError as error:
+ print >>sys.stderr, "arv-keepdocker:", error.message
sys.exit(1)
- elif not args.force:
+ if not args.force:
# Abort if this image is already in Arvados.
existing_links = arvados.api('v1').links().list(
filters=[['link_class', '=', 'docker_image_hash'],
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list