From ba34cc027563db7bcea984e9270eaaba4e9f49a3 Mon Sep 17 00:00:00 2001 From: Yu Qi Zhang Date: Fri, 10 Mar 2017 17:57:20 +0000 Subject: [PATCH] Fix filtering Change the format of "Created" for images to match containers, fix filtering for partial keywords, and update auto-complete and man pages. Signed-off-by: Yu Qi Zhang Closes: #923 Approved by: giuseppe --- Atomic/images.py | 11 ++++++----- Atomic/objects/image.py | 22 +++++++++++++++++----- bash/atomic | 5 +++-- docs/atomic-containers.1.md | 4 ++-- docs/atomic-images.1.md | 5 +++-- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Atomic/images.py b/Atomic/images.py index 817f093..f3fde29 100644 --- a/Atomic/images.py +++ b/Atomic/images.py @@ -187,7 +187,7 @@ class Images(Atomic): else: indicator = indicator + str(self.skull, "utf-8") + space _id = image.short_id if self.args.truncate else image.id - util.write_out(col_out.format(indicator, image.repo or "", image.tag or "", _id, image.timestamp, + util.write_out(col_out.format(indicator, image.repo or "", image.tag or "", _id, image.created[0:16], image.virtual_size, image.backend.backend)) util.write_out("") return @@ -241,7 +241,7 @@ class Images(Atomic): shutil.rmtree(tmpdir) def _filter_include_image(self, image_obj): - filterables = ["repo", "tag", "id", "created", "size", "type", "dangling"] + filterables = ["repo", "tag", "id", "image", "created", "size", "type", "is_dangling"] for i in self.args.filter: try: var, value = str(i).split("=") @@ -259,10 +259,11 @@ class Images(Atomic): "Please choose from {}".format(var, filterables)) if var == "type": var = "str_backend" - if getattr(image_obj, var, None).lower() != value.lower(): - return False - return True + if hasattr(image_obj, var) and value.lower() in str(getattr(image_obj, var)).lower(): + return True + + return False def _mark_used(self, images): assert isinstance(images, list) diff --git a/Atomic/objects/image.py b/Atomic/objects/image.py index 83a0968..af009c2 100644 --- a/Atomic/objects/image.py +++ b/Atomic/objects/image.py @@ -2,8 +2,9 @@ from Atomic.util import Decompose, output_json from Atomic.discovery import RegistryInspect from Atomic.objects.layer import Layer from Atomic.client import no_shaw +import datetime import math -import time +import numbers class Image(object): @@ -18,7 +19,7 @@ class Image(object): self.image = None self.tag = None self.repotags = None - self.created = None + self._created = None self.size = None self.original_structure = None self._backend = backend @@ -154,7 +155,7 @@ class Image(object): def populate_remote_inspect_info(self): remote_inspect_info = self.remote_inspect() - self.created = remote_inspect_info['Created'] + self._created = remote_inspect_info['Created'] self.name = remote_inspect_info['Name'] self.os = remote_inspect_info['Os'] self.digest = remote_inspect_info['Digest'] @@ -238,8 +239,19 @@ class Image(object): return self.id[:12] @property - def timestamp(self): - return time.strftime("%F %H:%M", time.localtime(self.created)) + def created(self): + if (isinstance(self._created, numbers.Number)): + return str(datetime.datetime.fromtimestamp(self._created)) + + return self._created + + @property + def created_raw(self): + return self._created + + @created.setter + def created(self, value): + self._created = value @property def type(self): diff --git a/bash/atomic b/bash/atomic index 62db3c0..e6e7a58 100644 --- a/bash/atomic +++ b/bash/atomic @@ -523,12 +523,12 @@ _atomic_containers_list() { " local filterables=" - id container image command created - status + state + backend runtime " @@ -799,6 +799,7 @@ _atomic_images_list() { created size type + is_dangling " local options_with_args_glob=$(__atomic_to_extglob "$options_with_args") diff --git a/docs/atomic-containers.1.md b/docs/atomic-containers.1.md index eeeea43..11323f7 100644 --- a/docs/atomic-containers.1.md +++ b/docs/atomic-containers.1.md @@ -70,9 +70,9 @@ Can use --set to update environment variables. Print all the installed containers **-f** **--filter** - Filter output based on given filters, example usage: `--filter id=foo` will list all containers that has "foo" as part of their ID. + Filter output based on given filters, example usage: `--filter container=foo` will list all containers that has "foo" as part of their container ID. - Filterables: `container (id)`, `image`, `command`, `created`, `status`, `runtime` + Filterables: `backend`, `command`, `container`, `created`, `image`, `runtime`, `state` **--json** Print in a machine parsable format diff --git a/docs/atomic-images.1.md b/docs/atomic-images.1.md index 8a7acd1..2860e2d 100644 --- a/docs/atomic-images.1.md +++ b/docs/atomic-images.1.md @@ -99,8 +99,9 @@ Atomic --assumeyes option can be used Show all images, including intermediate images [**-f|--filter**] - Filter output based on given filters, example usage: '--filter repo=foo' -will list all images that has "foo" as part of their repository name. + Filter output based on given filters, example usage: '--filter repo=foo' will list all images that has "foo" as part of their repository name. + + Filterables: `created`, `id`, `image`, `is_dangling`, `repo`, `size`, `tag`, `type` [**-n|--noheading**] Do not print heading when listing the images