mirror of
https://github.com/containers/podman.git
synced 2025-07-31 20:32:39 +08:00
Add support for --all in pypodman ps command
* Updated field widths to match changes in go code Fixes #1654 Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -16,6 +16,7 @@ class Ps(AbstractActionBase):
|
|||||||
"""Add Images command to parent parser."""
|
"""Add Images command to parent parser."""
|
||||||
parser = parent.add_parser('ps', help='list containers')
|
parser = parent.add_parser('ps', help='list containers')
|
||||||
super().subparser(parser)
|
super().subparser(parser)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--sort',
|
'--sort',
|
||||||
choices=('createdat', 'id', 'image', 'names', 'runningfor', 'size',
|
choices=('createdat', 'id', 'image', 'names', 'runningfor', 'size',
|
||||||
@ -32,9 +33,9 @@ class Ps(AbstractActionBase):
|
|||||||
|
|
||||||
self.columns = OrderedDict({
|
self.columns = OrderedDict({
|
||||||
'id':
|
'id':
|
||||||
ReportColumn('id', 'CONTAINER ID', 14),
|
ReportColumn('id', 'CONTAINER ID', 12),
|
||||||
'image':
|
'image':
|
||||||
ReportColumn('image', 'IMAGE', 30),
|
ReportColumn('image', 'IMAGE', 31),
|
||||||
'command':
|
'command':
|
||||||
ReportColumn('column', 'COMMAND', 20),
|
ReportColumn('column', 'COMMAND', 20),
|
||||||
'createdat':
|
'createdat':
|
||||||
@ -49,10 +50,15 @@ class Ps(AbstractActionBase):
|
|||||||
|
|
||||||
def list(self):
|
def list(self):
|
||||||
"""List containers."""
|
"""List containers."""
|
||||||
|
if self._args.all:
|
||||||
|
ictnrs = self.client.containers.list()
|
||||||
|
else:
|
||||||
|
ictnrs = filter(
|
||||||
|
lambda c: podman.FoldedString(c['status']) == 'running',
|
||||||
|
self.client.containers.list())
|
||||||
|
|
||||||
# TODO: Verify sorting on dates and size
|
# TODO: Verify sorting on dates and size
|
||||||
ctnrs = sorted(
|
ctnrs = sorted(ictnrs, key=operator.attrgetter(self._args.sort))
|
||||||
self.client.containers.list(),
|
|
||||||
key=operator.attrgetter(self._args.sort))
|
|
||||||
if not ctnrs:
|
if not ctnrs:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -65,9 +71,6 @@ class Ps(AbstractActionBase):
|
|||||||
'createdat':
|
'createdat':
|
||||||
humanize.naturaldate(podman.datetime_parse(ctnr.createdat)),
|
humanize.naturaldate(podman.datetime_parse(ctnr.createdat)),
|
||||||
})
|
})
|
||||||
|
|
||||||
if self._args.truncate:
|
|
||||||
fields.update({'image': ctnr.image[-30:]})
|
|
||||||
rows.append(fields)
|
rows.append(fields)
|
||||||
|
|
||||||
with Report(self.columns, heading=self._args.heading) as report:
|
with Report(self.columns, heading=self._args.heading) as report:
|
||||||
|
Reference in New Issue
Block a user