Skip to content

Commit

Permalink
Merge pull request #20 from clebergnu/py3k_aexpect_helper
Browse files Browse the repository at this point in the history
Python 3: fix aexpect-helper
  • Loading branch information
lmr committed Nov 20, 2017
2 parents 2abc84b + 1686e60 commit 5a3ec74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions aexpect/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def find_command(cmd, default=None):
:raise: :class:`aexpect.utils.path.CmdNotFoundError` in case the
command was not found and no default was given.
"""
common_bin_paths = ["/usr/libexec", "/usr/local/sbin", "/usr/local/bin",
"/usr/sbin", "/usr/bin", "/sbin", "/bin"]
try:
path_paths = os.environ['PATH'].split(":")
except IndexError:
path_paths = []
path_paths = list(set(common_bin_paths + path_paths))

for common_path in ["/usr/libexec", "/usr/local/sbin", "/usr/local/bin",
"/usr/sbin", "/usr/bin", "/sbin", "/bin"]:
if common_path not in path_paths:
path_paths.append(common_path)

for dir_path in path_paths:
cmd_path = os.path.join(dir_path, cmd)
Expand Down
10 changes: 5 additions & 5 deletions scripts/aexpect-helper
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -99,7 +99,7 @@ if __name__ == "__main__":
makestandard(shell_fd, echo)

server_log.info('Opening output file %s' % output_filename)
output_file = open(output_filename, "w")
output_file = open(output_filename, "wb")
server_log.info('Opening input pipe %s' % inpipe_filename)
os.mkfifo(inpipe_filename)
inpipe_fd = os.open(inpipe_filename, os.O_RDWR)
Expand All @@ -124,7 +124,7 @@ if __name__ == "__main__":
sys.stdout.flush()

# Initialize buffers
buffers = ["" for reader in readers]
buffers = [b"" for reader in readers]

# Read from child and write to files/pipes
server_log.info('Entering main read loop')
Expand Down Expand Up @@ -153,12 +153,12 @@ if __name__ == "__main__":
try:
data = os.read(shell_fd, 16384)
except OSError:
data = ""
data = b""
if not data:
check_termination = True
# Remove carriage returns from the data -- they often cause
# trouble and are normally not needed
data = data.replace("\r", "")
data = data.replace(b"\r", b"")
output_file.write(data)
output_file.flush()
for i in range(len(readers)):
Expand Down

0 comments on commit 5a3ec74

Please sign in to comment.