Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OSError when piping output of rf_logs.py #33

Merged
merged 4 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions redfish_utilities/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
with the log service for a given Redfish service
"""

import os
import shutil

from .messages import verify_response
from enum import Enum
Expand Down Expand Up @@ -75,7 +75,7 @@ def print_log_entries( log_entries, details = False ):
"""

# Set up templates
console_size = os.get_terminal_size()
console_size = shutil.get_terminal_size(fallback=(80, 24))
message_size = console_size.columns - 38
entry_line_format = " {:5s} | {:25s} | {}"
detail_line_format = " {:33s} | {}: {}"
Expand Down
5 changes: 5 additions & 0 deletions scripts/rf_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"""

import argparse
import sys

import redfish
import redfish_utilities

Expand Down Expand Up @@ -58,5 +60,8 @@
# Print log was requested
log_entries = redfish_utilities.get_log_entries( redfish_obj, container_type, container_id, args.log )
redfish_utilities.print_log_entries( log_entries, args.details )
except BrokenPipeError:
pass
finally:
redfish_obj.logout()
sys.stderr.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be brought into the lower level print routine? I'd rather not create a burden on callers doing this since the "redfish_utilities" folder is supposed to be treated as a library others might use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the catch of BrokenPipeError to print_log_entries(). But I left the sys.stderr.close() here because that seemed to be the only way to eliminate this extraneous message when piping to head:

Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe