mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Fix long image name handling
* Fixed issue where podman printed '<none>' and pypodman skipped the image * Fixed issue where port was printed in place of tags Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -37,7 +37,7 @@ class Images(AbstractActionBase):
|
|||||||
|
|
||||||
self.columns = OrderedDict({
|
self.columns = OrderedDict({
|
||||||
'name':
|
'name':
|
||||||
ReportColumn('name', 'REPOSITORY', 40),
|
ReportColumn('name', 'REPOSITORY', 0),
|
||||||
'tag':
|
'tag':
|
||||||
ReportColumn('tag', 'TAG', 10),
|
ReportColumn('tag', 'TAG', 10),
|
||||||
'id':
|
'id':
|
||||||
@ -71,12 +71,12 @@ class Images(AbstractActionBase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
for r in image.repoTags:
|
for r in image.repoTags:
|
||||||
name, tag = r.split(':', 1)
|
name, tag = r.rsplit(':', 1)
|
||||||
fields.update({
|
fields.update({
|
||||||
'name': name,
|
'name': name,
|
||||||
'tag': tag,
|
'tag': tag,
|
||||||
})
|
})
|
||||||
rows.append(fields)
|
rows.append(fields)
|
||||||
|
|
||||||
if not self._args.digests:
|
if not self._args.digests:
|
||||||
del self.columns['repoDigests']
|
del self.columns['repoDigests']
|
||||||
|
@ -1,8 +1,23 @@
|
|||||||
"""Report Manager."""
|
"""Report Manager."""
|
||||||
|
import string
|
||||||
import sys
|
import sys
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
class ReportFormatter(string.Formatter):
|
||||||
|
"""Custom formatter to default missing keys to '<none>'."""
|
||||||
|
|
||||||
|
def get_value(self, key, args, kwargs):
|
||||||
|
"""Map missing key to value '<none>'."""
|
||||||
|
try:
|
||||||
|
if isinstance(key, int):
|
||||||
|
return args[key]
|
||||||
|
else:
|
||||||
|
return kwargs[key]
|
||||||
|
except KeyError:
|
||||||
|
return '<none>'
|
||||||
|
|
||||||
|
|
||||||
class ReportColumn(namedtuple('ReportColumn', 'key display width default')):
|
class ReportColumn(namedtuple('ReportColumn', 'key display width default')):
|
||||||
"""Hold attributes of output column."""
|
"""Hold attributes of output column."""
|
||||||
|
|
||||||
@ -26,18 +41,24 @@ class Report():
|
|||||||
"""
|
"""
|
||||||
self._columns = columns
|
self._columns = columns
|
||||||
self._file = file
|
self._file = file
|
||||||
|
self._format_string = None
|
||||||
|
self._formatter = ReportFormatter()
|
||||||
self._heading = heading
|
self._heading = heading
|
||||||
self.epilog = epilog
|
self.epilog = epilog
|
||||||
self._format = None
|
|
||||||
|
|
||||||
def row(self, **fields):
|
def row(self, **fields):
|
||||||
"""Print row for report."""
|
"""Print row for report."""
|
||||||
if self._heading:
|
if self._heading:
|
||||||
hdrs = {k: v.display for (k, v) in self._columns.items()}
|
hdrs = {k: v.display for (k, v) in self._columns.items()}
|
||||||
print(self._format.format(**hdrs), flush=True, file=self._file)
|
print(
|
||||||
|
self._formatter.format(self._format_string, **hdrs),
|
||||||
|
flush=True,
|
||||||
|
file=self._file,
|
||||||
|
)
|
||||||
self._heading = False
|
self._heading = False
|
||||||
|
|
||||||
fields = {k: str(v) for k, v in fields.items()}
|
fields = {k: str(v) for k, v in fields.items()}
|
||||||
print(self._format.format(**fields))
|
print(self._formatter.format(self._format_string, **fields))
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
"""Return `self` upon entering the runtime context."""
|
"""Return `self` upon entering the runtime context."""
|
||||||
@ -63,4 +84,4 @@ class Report():
|
|||||||
display_len = info.width
|
display_len = info.width
|
||||||
|
|
||||||
fmt.append('{{{0}:{1}.{1}}}'.format(key, display_len))
|
fmt.append('{{{0}:{1}.{1}}}'.format(key, display_len))
|
||||||
self._format = ' '.join(fmt)
|
self._format_string = ' '.join(fmt)
|
||||||
|
Reference in New Issue
Block a user