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 decoding errors in scripts/common.py's execute_cmd #295

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ def execute(cmd, abort = True):
status = p.returncode
if debug:
message = 'Execution of "{0}" returned with exit code {1}\n'.format(cmd, status)
message += ' stdout: "{0}"\n'.format(stdout.decode('ascii').rstrip('\n'))
message += ' stderr: "{0}"'.format(stderr.decode('ascii').rstrip('\n'))
message += ' stdout: "{0}"\n'.format(stdout.decode('ascii', 'ignore').rstrip('\n'))
message += ' stderr: "{0}"'.format(stderr.decode('ascii', 'ignore').rstrip('\n'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Normally, I would use argument names for optional arguments:

stdout.decode(encoding='ascii', errors='ignore')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added the argument names as requested, thanks for the suggestion.

logging.debug(message)
if not status == 0:
message = 'Execution of command {0} failed, exit code {1}\n'.format(cmd, status)
message += ' stdout: "{0}"\n'.format(stdout.decode('ascii').rstrip('\n'))
message += ' stderr: "{0}"'.format(stderr.decode('ascii').rstrip('\n'))
message += ' stdout: "{0}"\n'.format(stdout.decode('ascii', 'ignore').rstrip('\n'))
message += ' stderr: "{0}"'.format(stderr.decode('ascii', 'ignore').rstrip('\n'))
if abort:
raise Exception(message)
else:
logging.error(message)
return (status, stdout.decode('ascii').rstrip('\n'), stderr.decode('ascii').rstrip('\n'))
return (status, stdout.decode('ascii', 'ignore').rstrip('\n'),
stderr.decode('ascii', 'ignore').rstrip('\n'))

def split_var_name_and_array_reference(var_name):
"""Split an expression like foo(:,a,1:ddt%ngas)
Expand Down