Skip to content

Commit

Permalink
add images command
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammed Tayeh <m.tayeh94@gmail.com>
  • Loading branch information
tayeh committed Jun 23, 2023
1 parent 3890eac commit 13ab841
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,35 @@ def compose_kill(compose, args):
compose.podman.run([], "kill", podman_args)


@cmd_run(podman_compose, "images", "List images used by the created containers")
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())
else:
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())

# Determine the maximum length of each column
column_widths = [max(map(len, column)) for column in zip(*data)]

# Print each row
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))


###################
# command arguments parsing
###################
Expand Down Expand Up @@ -3081,6 +3110,12 @@ 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"
)


def main():
podman_compose.run()
Expand Down

0 comments on commit 13ab841

Please sign in to comment.