Skip to content

Commit

Permalink
Add images command
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammed Tayeh <[email protected]>
  • Loading branch information
tayeh authored and p12tic committed Apr 28, 2024
1 parent 26b051c commit 43e3794
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2852,22 +2852,29 @@ async def compose_stats(compose, args):


@cmd_run(podman_compose, "images", "List images used by the created containers")
def compose_images(compose, args):
async def compose_images(compose, args):
img_containers = [cnt for cnt in compose.containers if "image" in cnt]
data = []
if args.quiet is True:
for img in img_containers:
name = img['name']
data.append(compose.podman.output(
[], "images", ["--quiet", img['image']]
).decode("utf-8").split())
name = img["name"]
output = await compose.podman.output([], "images", ["--quiet", img["image"]])
data.append(output.decode("utf-8").split())
else:
data.append(['CONTAINER', 'REPOSITORY', 'TAG', 'IMAGE ID', 'SIZE', ''])
data.append(["CONTAINER", "REPOSITORY", "TAG", "IMAGE ID", "SIZE", ""])
for img in img_containers:
name = img['name']
data.append(compose.podman.output(
[], "images", ["--format", "table " + name + " {{.Repository}} {{.Tag}} {{.ID}} {{.Size}}", "-n", img['image']]
).decode("utf-8").split())
name = img["name"]
output = await compose.podman.output(
[],
"images",
[
"--format",
"table " + name + " {{.Repository}} {{.Tag}} {{.ID}} {{.Size}}",
"-n",
img["image"],
],
)
data.append(output.decode("utf-8").split())

# Determine the maximum length of each column
column_widths = [max(map(len, column)) for column in zip(*data)]
Expand All @@ -2876,8 +2883,8 @@ def compose_images(compose, args):
for row in data:
# Format each cell using the maximum column width
formatted_row = [cell.ljust(width) for cell, width in zip(row, column_widths)]
formatted_row[-2:] = [''.join(formatted_row[-2:]).strip()]
print('\t'.join(formatted_row))
formatted_row[-2:] = ["".join(formatted_row[-2:]).strip()]
print("\t".join(formatted_row))


###################
Expand Down Expand Up @@ -3313,11 +3320,10 @@ def compose_kill_parse(parser):
action="store_true",
)


@cmd_parse(podman_compose, "images")
def compose_images_parse(parser):
parser.add_argument(
"-q", "--quiet", help="Only display images IDs", action="store_true"
)
parser.add_argument("-q", "--quiet", help="Only display images IDs", action="store_true")


@cmd_parse(podman_compose, ["stats"])
Expand Down

0 comments on commit 43e3794

Please sign in to comment.