mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-29 00:08:59 -04:00

*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
99 lines
2.7 KiB
Python
99 lines
2.7 KiB
Python
"""This is like pexpect, but will work on any file descriptor that you pass it.
|
|
So you are reponsible for opening and close the file descriptor.
|
|
|
|
$Id: fdpexpect.py 505 2007-12-26 21:33:50Z noah $
|
|
"""
|
|
|
|
from pexpect import *
|
|
import os
|
|
|
|
__all__ = ['fdspawn']
|
|
|
|
|
|
class fdspawn (spawn):
|
|
|
|
"""This is like pexpect.spawn but allows you to supply your own open file
|
|
descriptor. For example, you could use it to read through a file looking
|
|
for patterns, or to control a modem or serial device. """
|
|
|
|
def __init__(
|
|
self,
|
|
fd,
|
|
args=[],
|
|
timeout=30,
|
|
maxread=2000,
|
|
searchwindowsize=None,
|
|
logfile=None):
|
|
"""This takes a file descriptor (an int) or an object that support the
|
|
fileno() method (returning an int). All Python file-like objects
|
|
support fileno(). """
|
|
|
|
# TODO: Add better handling of trying to use fdspawn in place of spawn
|
|
# TODO: (overload to allow fdspawn to also handle commands as spawn
|
|
# does.
|
|
|
|
if not isinstance(fd, type(0)) and hasattr(fd, 'fileno'):
|
|
fd = fd.fileno()
|
|
|
|
if not isinstance(fd, type(0)):
|
|
raise ExceptionPexpect(
|
|
'The fd argument is not an int. If this is a command string then maybe you want to use pexpect.spawn.')
|
|
|
|
try: # make sure fd is a valid file descriptor
|
|
os.fstat(fd)
|
|
except OSError:
|
|
raise ExceptionPexpect(
|
|
'The fd argument is not a valid file descriptor.')
|
|
|
|
self.args = None
|
|
self.command = None
|
|
spawn.__init__(
|
|
self,
|
|
None,
|
|
args,
|
|
timeout,
|
|
maxread,
|
|
searchwindowsize,
|
|
logfile)
|
|
self.child_fd = fd
|
|
self.own_fd = False
|
|
self.closed = False
|
|
self.name = '<file descriptor %d>' % fd
|
|
|
|
def __del__(self):
|
|
|
|
return
|
|
|
|
def close(self):
|
|
|
|
if self.child_fd == -1:
|
|
return
|
|
if self.own_fd:
|
|
self.close(self)
|
|
else:
|
|
self.flush()
|
|
os.close(self.child_fd)
|
|
self.child_fd = -1
|
|
self.closed = True
|
|
|
|
def isalive(self):
|
|
"""This checks if the file descriptor is still valid. If os.fstat()
|
|
does not raise an exception then we assume it is alive. """
|
|
|
|
if self.child_fd == -1:
|
|
return False
|
|
try:
|
|
os.fstat(self.child_fd)
|
|
return True
|
|
except:
|
|
return False
|
|
|
|
def terminate(self, force=False):
|
|
|
|
raise ExceptionPexpect(
|
|
'This method is not valid for file descriptors.')
|
|
|
|
def kill(self, sig):
|
|
|
|
return
|