Juan Hernandez has uploaded a new change for review.
Change subject: cli: Don't break long values
......................................................................
cli: Don't break long values
Currently when the value of a field is very long, we try to break it so
that it will take several lines. For example:
[RHEVM shell (connected)]# show something
id : ee34f1fb-308d-494f-a084-f58ec5b35b87
very-long-field : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxx
But the actual result isn't correctlly aligned due to an error in the
way we format the columns. In addition this formatting isn't useful for
users that want to copy and paste the text, as the copied text will
include spaces that the user will have to manually remove. To avoid the
issue alltogheter this patch changes the CLI so that it won't try to
break the lines. The result will be like this:
[RHEVM shell (connected)]# show something
id : ee34f1fb-308d-494f-a084-f58ec5b35b87
very-long-field : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx
This patch also changes the default options of the "less" pager so that
it won't break long lines.
Change-Id: I8b8b7d1abcaa40a16c3be9fc26a8591b061cd103
Bug-Url: https://bugzilla.redhat.com/1077806
Signed-off-by: Juan Hernandez <[email protected]>
---
M src/cli/platform/posix/util.py
M src/ovirtcli/format/text.py
2 files changed, 5 insertions(+), 17 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-cli refs/changes/45/27845/1
diff --git a/src/cli/platform/posix/util.py b/src/cli/platform/posix/util.py
index 605ff48..70bd9af 100644
--- a/src/cli/platform/posix/util.py
+++ b/src/cli/platform/posix/util.py
@@ -54,7 +54,7 @@
"""Return the platform specific pager."""
pager = os.environ.get('PAGER')
if pager is None and which('less'):
- pager = 'less -FSRX'
+ pager = 'less -FRX'
if pager is None and which('more'):
pager = 'more'
return pager
diff --git a/src/ovirtcli/format/text.py b/src/ovirtcli/format/text.py
index ade7390..1ca9921 100644
--- a/src/ovirtcli/format/text.py
+++ b/src/ovirtcli/format/text.py
@@ -118,7 +118,7 @@
width0 = max(width0, len(new_field))
return width0
- def __write_context(self, format0, format1, width1, field, value,
resource_context, reduced_mode_fields, mode=FormatMode.FULL, resource=None,
parent=None):
+ def __write_context(self, format0, field, value, resource_context,
reduced_mode_fields, mode=FormatMode.FULL, resource=None, parent=None):
context = self.context
stdout = context.terminal.stdout
@@ -142,14 +142,8 @@
if mode != FormatMode.REDUCED or fil in reduced_mode_fields:
stdout.write(format0 % fil)
stdout.write(': ')
- stdout.write(format1 % val)
+ stdout.write(val)
stdout.write('\n')
- val = val[width1:]
- while len(val) > 0:
- stdout.write(width1 * ' ')
- stdout.write(format1 % val)
- stdout.write('\n')
- val = val[width1:]
def _format_resource(self, resource, width= -1, show_empty=False,
resource_context=None, mode=FormatMode.FULL, sort_strategy=['id', 'name',
'description'], parent=None):
context = self.context
@@ -173,12 +167,6 @@
width0 = max(width0, len(item))
format0 = '%%-%ds' % width0
- if stdout.isatty() and not settings['ovirt-shell:wide']:
- width1 = context.terminal.width - width0 - 2
- format1 = '%%-%d.%ds' % (width1, width1)
- else:
- width1 = sys.maxint
- format1 = '%s'
for field in fields:
if field not in fields_exceptions:
@@ -210,7 +198,7 @@
if value == None and show_empty == True:
value = ''
elif value == None: continue
- self.__write_context(format0, format1, width1, field,
value, resource_context, reduced_mode_fields=reduced_mode_fields, mode=mode,
parent=parent, resource=resource)
+ self.__write_context(format0, field, value,
resource_context, reduced_mode_fields=reduced_mode_fields, mode=mode,
parent=parent, resource=resource)
else:
if hasattr(params, type(value).__name__) or
hasattr(brokers, type(value).__name__):
if resource_context is not None:
@@ -231,7 +219,7 @@
if value == None and show_empty == True:
value = ''
elif value == None: continue
- self.__write_context(format0, format1, width1, field,
value, resource_context, reduced_mode_fields=reduced_mode_fields, mode=mode,
parent=parent, resource=resource)
+ self.__write_context(format0, field, value,
resource_context, reduced_mode_fields=reduced_mode_fields, mode=mode,
parent=parent, resource=resource)
def _get_max_field_width_in_collection(self, collection, mode):
fields_exceptions = ['link', 'href', 'parentclass', '_Base__context']
--
To view, visit http://gerrit.ovirt.org/27845
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8b8b7d1abcaa40a16c3be9fc26a8591b061cd103
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-cli
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches