output is line-wrapped

Bug #1577368 reported by Vincent Legoll
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cliff
Fix Released
Undecided
Vincent Legoll
python-openstackclient
Invalid
Undecided
Unassigned

Bug Description

I'm trying to write a BASH-based jupyter-notebook to teach openstack CLI clients usage.

The output from old-style clients (nova, cinder, etc...) is good whereas the output from the new all-in-one client (openstack)
is line wrapped, as if the command was run in a 80x25 terminal.

I've not found any way to force the output back to no-line-wrapping mode, is there one ?

This looks like a regression from old clients to the new one...

Revision history for this message
Vincent Legoll (vincent-legoll) wrote :

The attached screen capture does show the old clients output, which is not line-wrapped (at least not in a way that shows here) whereas the new-style openstack client is wrapped as if in a 80x25 terminal...

Revision history for this message
Steve Martinelli (stevemar) wrote :
Revision history for this message
Steve Martinelli (stevemar) wrote :

@Vincent, can you confirm that using "--max-width <some number>" fixes the issue? I'm wondering why cliff is detecting such a small area for your application

Changed in python-openstackclient:
status: New → Invalid
Revision history for this message
Vincent Legoll (vincent-legoll) wrote :

Yes this bug is actually related to those cited, but on the opposite end.

I want to be able to disable the terminal size settings detection, and yes --max-width can help with that.

But it would even be better if an environment variable could do the same, so that I can set it only once per session's needs, and make that hidden from the view of my students, to avoid polluting the already steep learning curve with cosmetic options.

Revision history for this message
Doug Hellmann (doug-hellmann) wrote :

@Vincent, do you want to show the output of the command as-is in the notebook, or are you trying to parse the results?

Revision history for this message
Doug Hellmann (doug-hellmann) wrote :

I would support adding an environment variable to disable the size-setting feature of the table formatter entirely.

Revision history for this message
Steve Baker (steve-stevebaker) wrote :
Revision history for this message
Steve Baker (steve-stevebaker) wrote :

Vincent, jupyter-notebook must be doing some magic to pretend there is a tty. An easy workaround for this would be to pipe your openstack commands to cat (assuming you can make this transparent to notebook users).

But yes, I'd support an env var to turn off tty detection

Revision history for this message
Vincent Legoll (vincent-legoll) wrote :

I'm not parsing output, just displaying it in the notebook. Piping through cat would be no better than using --max-width, though.

So either it's enhanced with an env. var. or I'd rather use the CLI parameter.

Revision history for this message
Vincent Legoll (vincent-legoll) wrote :
Revision history for this message
Vincent Legoll (vincent-legoll) wrote :

I volunteer doing it (add env var(s)) if the idea is pre-approved upfront.

Revision history for this message
Steve Martinelli (stevemar) wrote :

@vincent, you have my vote for env var :)

Revision history for this message
Steve Martinelli (stevemar) wrote :

You could probably get away with just changing:

https://github.com/openstack/cliff/blob/d171567ebad8a1579597cefc3d96a9686722ae5b/cliff/formatters/table.py#L28

from: default=0,
to: default=os.environ.get('MAX_WIDTH', None)

or something like that

Revision history for this message
Vincent Legoll (vincent-legoll) wrote :

Thanks for finding the right place in the code, but the really contentious thing will be the env. var. naming, no ? :-)

Proper naming is hard and opinionated, I'd vote for OS_ prefixing to avoid namespace collisions...

I'd have something in the name that explains which width we are talking about : TERM or OUT, or...

What about OS_MAX_TERM_WIDTH ?

Changed in python-cliff:
assignee: nobody → Vincent Legoll (vincent-legoll)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cliff (master)

Fix proposed to branch: master
Review: https://review.openstack.org/312462

Changed in python-cliff:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/312469

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on cliff (master)

Change abandoned by Vincent Legoll (<email address hidden>) on branch: master
Review: https://review.openstack.org/312462
Reason: missing import

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cliff (master)

Reviewed: https://review.openstack.org/312469
Committed: https://git.openstack.org/cgit/openstack/cliff/commit/?id=c59f04465cff2d2d147491d5ec521e8b769bd377
Submitter: Jenkins
Branch: master

commit c59f04465cff2d2d147491d5ec521e8b769bd377
Author: Vincent Legoll <email address hidden>
Date: Sat May 7 18:33:35 2016 +0200

    Add CLIFF_MAX_TERM_WIDTH envvar to complement --max-width

    Some cliff clients tailors their output according to characteristics
    of the terminal they outputs text to. They detect the width of the
    terminal in order to pretty print text properly cut to line length.

    There are situations where the output is not in a "real" terminal
    but in some kind of emulation or redirected layer for which this
    line length interpretation is not ideal. For example in a bash
    jupyter-notebook.

    There already exist the --max-width CLI parameter to allow that
    to be customized, but there are cases where you don't want to
    use an additional parameter. So add an environment variable
    that has the same meaning, to help avoiding the use of
    --max-width.

    Without the parameter nor the envvar, the behaviour should stay
    the same as before the patch, i.e. the output is cut to terminal
    line length. The envvar is then used to give the parameter's
    default value, so the parameter will stay being the final one
    deciding of the behaviour when used.

    Add mock'ed testing for the new CLIFF_MAX_TERM_WIDTH envvar.
    Add mock'ed tests to ensure parameter vs envvar priority.
    Add testing for actual parameter parsing & priority vs envvar.²

    This has been discussed in:
    https://bugs.launchpad.net/python-openstackclient/+bug/1577368
    https://bugs.launchpad.net/python-cliff/+bug/1485847/comments/7

    Closes-Bug: 1577368
    Related-Bug: 1485847

    Change-Id: I0ab988ea0e7087960a9bfb2353f46918f0333a53
    Signed-off-by: Vincent Legoll <email address hidden>

Changed in python-cliff:
status: In Progress → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/cliff 2.1.0

This issue was fixed in the openstack/cliff 2.1.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.