Ravi Nori has uploaded a new change for review. Change subject: cli: list xxx --show all - output is not well formatted(#890038) ......................................................................
cli: list xxx --show all - output is not well formatted(#890038) There are indentation differences between the listed devices when there are extra fields in some devices. Change-Id: Ibcaa28d3718f8dd0aceb3935ae2606713eee34e9 Bug-Url: https://bugzilla.redhat.com/890038 Signed-off-by: Ravi Nori <rn...@redhat.com> --- M src/ovirtcli/format/text.py 1 file changed, 29 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/40/21240/1 diff --git a/src/ovirtcli/format/text.py b/src/ovirtcli/format/text.py index f3e1f33..73cf780 100644 --- a/src/ovirtcli/format/text.py +++ b/src/ovirtcli/format/text.py @@ -221,17 +221,46 @@ elif value == None: continue self.__write_context(format0, format1, width1, field, value, resource_context, reduced_mode_fields=reduced_mode_fields, mode=mode) + def _get_max_field_width_in_collection(self, collection, show_empty=False, resource_context=None, sort_strategy=['id', 'name', 'description']): + fields_exceptions = ['link', 'href', 'parentclass', '_Base__context'] + reduced_mode_fields = ['id', 'name', 'description'] + + width = -1 + mode= (FormatMode.REDUCED if not show_empty + else FormatMode.FULL) + + for resource in collection: + width0 = -1 + if mode == FormatMode.FULL: + fields = self.sort_fields(self._get_fields(resource), sort_strategy) + width0 = self.__get_max_field_width((resource.superclass if isinstance(resource, Base) + else resource), + fields_exceptions, + -1, show_empty, + resource_context, + mode=mode) + else: + for item in reduced_mode_fields: + width0 = max(width0, len(item)) + width = max(width, width0) + + return width + def _format_collection(self, collection, show_empty=False): context = self.context stdout = context.terminal.stdout + width = -1 + for resource in collection: if isinstance(resource, Base): self._format_resource(resource=resource.superclass, + width=self._get_max_field_width_in_collection(collection, show_empty), mode=FormatMode.REDUCED if not show_empty else FormatMode.FULL) else: self._format_resource(resource=resource, + width=self._get_max_field_width_in_collection(collection, show_empty), mode=FormatMode.REDUCED if not show_empty else FormatMode.FULL) stdout.write('\n') -- To view, visit http://gerrit.ovirt.org/21240 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibcaa28d3718f8dd0aceb3935ae2606713eee34e9 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-cli Gerrit-Branch: master Gerrit-Owner: Ravi Nori <rn...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches