simpler function for dumping bytes to stdout

This commit is contained in:
Mike McLean 2019-03-01 12:28:11 -05:00
parent 0c2f0ea7c5
commit b4b6e2e6cc
2 changed files with 12 additions and 3 deletions

View file

@ -358,6 +358,15 @@ def write_to_stdout(contents):
contents = bytes.decode(sys.stdout.encoding, 'strict')
sys.stdout.write(contents)
def bytes_to_stdout(contents):
"""Helper function for writing bytes to stdout"""
if six.PY2:
sys.stdout.write(contents)
else:
sys.stdout.buffer.write(contents)
def watch_logs(session, tasklist, opts, poll_interval):
print("Watching logs (this may be safely interrupted)...")
@ -406,7 +415,7 @@ def watch_logs(session, tasklist, opts, poll_interval):
sys.stdout.write("\n")
sys.stdout.write("==> %s <==\n" % currlog)
lastlog = currlog
write_to_stdout(contents)
bytes_to_stdout(contents)
if opts.follow:

View file

@ -5,7 +5,7 @@ import time
import koji
from koji.plugin import export_cli
from koji_cli.lib import _, activate_session, OptionParser, watch_tasks, \
list_task_output_all_volumes, write_to_stdout
list_task_output_all_volumes, bytes_to_stdout
import six
@ -98,7 +98,7 @@ def handle_runroot(options, session, args):
log = session.downloadTaskOutput(task_id, 'runroot.log', volume=volume)
# runroot output, while normally text, can be *anything*, so
# treat it as binary
write_to_stdout(log)
bytes_to_stdout(log)
info = session.getTaskInfo(task_id)
if info is None:
sys.exit(1)