Esempio n. 1
0
def label_search(self, key=None, value=None):
    '''search across labels'''

    if key is not None:
        key = key.lower()

    if value is not None:
        value = value.lower()

    show_details = True
    if key is None and value is None:
        url = '%s/labels/search' % (self.base)
        show_details = False

    elif key is not None and value is not None:
        url = '%s/labels/search/%s/key/%s/value' % (self.base, key, value)

    elif key is None:
        url = '%s/labels/search/%s/value' % (self.base, value)

    else:
        url = '%s/labels/search/%s/key' % (self.base, key)

    result = self.get(url)
    if len(result) == 0:
        bot.info("No labels found.")
        sys.exit(0)

    bot.info("Labels\n")

    rows = []
    for l in result:
        if show_details is True:
            entry = [
                "%s:%s" % (l['key'], l['value']),
                "\n%s\n\n" % "\n".join(l['containers'])
            ]
        else:
            entry = [
                "N=%s" % len(l['containers']),
                "%s:%s" % (l['key'], l['value'])
            ]
        rows.append(entry)
    bot.table(rows)
Esempio n. 2
0
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)
Esempio n. 3
0
def search(self):
    '''a "show all" search that doesn't require a query'''

    url = '%s/collections/' % self.base

    results = self.paginate_get(url)

    if len(results) == 0:
        bot.info("No container collections found.")
        sys.exit(1)

    bot.info("Collections")

    rows = []
    for result in results:
        if "containers" in result:
            for c in result['containers']:
                rows.append([c['uri'], c['detail']])

    bot.table(rows)
Esempio n. 4
0
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()