def pull(self, images, file_name=None, decompress=True): bot.debug('Execution of PULL for %s images' % len(images)) for image in images: # If we need to decompress, it's old ext3 format if decompress is True: ext = 'img.gz' else: ext = 'simg' # squashfs q = parse_image_name(image, ext=ext) # Verify image existence, and obtain id url = "%s/container/%s/%s:%s" % (self.base, q['collection'], q['image'], q['tag']) bot.debug('Retrieving manifest at %s' % url) manifest = self.get(url) bot.debug(manifest) if file_name is None: file_name = q['storage'].replace('/', '-') image_file = self.download(url=manifest['image'], file_name=file_name, show_progress=True) bot.debug('Retrieved image file %s' % image_file) if os.path.exists(image_file) and decompress is True: # If compressed, decompress try: cli = Singularity() sys.stdout.write('Decompressing image ') bot.spinner.start() image_file = cli.decompress(image_file, quiet=True) except KeyboardInterrupt: bot.warning('Decompression cancelled.') except: bot.info('Image is not compressed.') image_name = image_file.replace('.gz', '') image_file = shutil.move(image_file, image_name) pass bot.spinner.stop() bot.custom(prefix="Success!", message=image_file)
def collection_search(self, query): '''collection search will list all containers for a specific collection. We assume query is the name of a collection''' query = query.lower().strip('/') url = '%s/collection/%s' % (self.base, query) result = self.get(url) if len(result) == 0: bot.info("No collections found.") sys.exit(1) bot.custom(prefix="COLLECTION", message=query) rows = [] for container in result['containers']: rows.append([container['uri'], container['detail']]) bot.table(rows)
def container_search(self, query, across_collections=False, environment=False, deffile=False, runscript=False, test=False): '''search for a specific container. If across collections is False, the query is parsed as a full container name and a specific container is returned. If across_collections is True, the container is searched for across collections. If across collections is True, details are not shown''' query = query.lower().strip('/') q = parse_image_name(query, defaults=False) if q['tag'] is not None: if across_collections is True: url = '%s/container/search/name/%s/tag/%s' % (self.base, q['image'], q['tag']) else: url = '%s/container/search/collection/%s/name/%s/tag/%s' % ( self.base, q['collection'], q['image'], q['tag']) elif q['tag'] is None: if across_collections is True: url = '%s/container/search/name/%s' % (self.base, q['image']) else: url = '%s/container/search/collection/%s/name/%s' % ( self.base, q['collection'], q['image']) result = self.get(url) if "containers" in result: result = result['containers'] if len(result) == 0: bot.info("No containers found.") sys.exit(1) bot.info("Containers %s" % query) rows = [] for c in result: # Convert date to readable thing datetime_object = parser.parse(c['add_date']) print_date = datetime_object.strftime('%b %d, %Y %I:%M%p') rows.append( ['%s/%s' % (c['collection'], c['name']), c['tag'], print_date]) bot.table(rows) # Finally, show metadata and other values if test is True or deffile is True or environment is True or runscript is True: bot.newline() for c in result: metadata = c['metadata'] if test is True: bot.custom(prefix='%test', message=metadata['test'], color="CYAN") bot.newline() if deffile is True: bot.custom(prefix='Singularity', message=metadata['deffile'], color="CYAN") bot.newline() if environment is True: bot.custom(prefix='%environment', message=metadata['environment'], color="CYAN") bot.newline() if runscript is True: bot.custom(prefix='%runscript', message=metadata['runscript'], color="CYAN") bot.newline()