FAQ
Hi. I'd like to capture the highstate job output with the terminal codes
like what --force-color provides the CLI. Is that possible in a Python
script?

I can run runner.cmd('jobs.lookup_jid', ["job-id"]) and see the colored
output in my terminal and the raw data. If I save the return value to a
variable all I see is the colored output. I've tried to redirect stdout to
a StringIO() object which only writes the text without color codes.

I'm assuming it's the terminal mode my script is running and I don't know
how to run it so that the terminal color codes are displayed.

Any guidance is appreciated.

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Justin Findlay at May 5, 2015 at 4:55 pm

    On 04/29/2015 02:50 PM, sandiegophp@gmail.com wrote:
    Hi. I'd like to capture the highstate job output with the terminal codes
    like what --force-color provides the CLI. Is that possible in a Python
    script?

    I can run runner.cmd('jobs.lookup_jid', ["job-id"]) and see the colored
    output in my terminal and the raw data. If I save the return value to a
    variable all I see is the colored output.
    I'm confused here. I'm assuming you want the colorized text output from
    salt, but then you're saying that's what you get? What am I
    misunderstanding?
    I've tried to redirect stdout
    to a StringIO() object which only writes the text without color codes.

    I'm assuming it's the terminal mode my script is running and I don't
    know how to run it so that the terminal color codes are displayed.

    Justin

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colton Myers at May 12, 2015 at 5:04 pm
    Off the top of my head I'm not sure how to capture this output with codes
    intact. By design when you pipe colored text into a python script, I think
    it removes the color codes, not sure if that's the shell that removes them
    or python. I do know that if you pipe `--force-color` output into less you
    see color codes...

    I'm honestly thinking your best bet would be to create a custom outputter,
    based on the highstate outputter, which print the `repr()` of the output
    strings, rather than the output strings themselves. That will (hopefully)
    escape the color codes and you'll be able to read them in on the other side.

    Or even better, use the python client API, get the data from the highstate,
    and then pipe it through a module based on the highstate outputter which
    just formats the output and returns it, rather than printing it. Then you
    take the shell out of the mix altogether.

    Anyway, sorry this is a little ramble-y, but hopefully it's helpful.

    --
    Colton Myers
    Platform Engineer, SaltStack
    @basepi on Twitter/Github/IRC
    On Wed, Apr 29, 2015 at 2:50 PM, wrote:

    Hi. I'd like to capture the highstate job output with the terminal codes
    like what --force-color provides the CLI. Is that possible in a Python
    script?

    I can run runner.cmd('jobs.lookup_jid', ["job-id"]) and see the colored
    output in my terminal and the raw data. If I save the return value to a
    variable all I see is the colored output. I've tried to redirect stdout to
    a StringIO() object which only writes the text without color codes.

    I'm assuming it's the terminal mode my script is running and I don't know
    how to run it so that the terminal color codes are displayed.

    Any guidance is appreciated.

    --
    You received this message because you are subscribed to the Google Groups
    "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsalt-users @
postedApr 29, '15 at 8:50p
activeMay 12, '15 at 5:04p
posts3
users3

People

Translate

site design / logo © 2021 Grokbase