本文整理汇总了Python中tty.tcsetattr函数的典型用法代码示例。如果您正苦于以下问题:Python tcsetattr函数的具体用法?Python tcsetattr怎么用?Python tcsetattr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tcsetattr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _spawn
def _spawn(shell, master_read):
"""Create a spawned process.
Modified version of pty.spawn with terminal size support.
"""
pid, master_fd = pty.fork()
if pid == pty.CHILD:
os.execlp(shell, shell)
try:
mode = tty.tcgetattr(pty.STDIN_FILENO)
tty.setraw(pty.STDIN_FILENO)
restore = True
except tty.error: # This is the same as termios.error
restore = False
_set_pty_size(master_fd)
signal.signal(signal.SIGWINCH, lambda *_: _set_pty_size(master_fd))
try:
pty._copy(master_fd, master_read, pty._read)
except OSError:
if restore:
tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(master_fd)
return os.waitpid(pid, 0)[1]
开发者ID:bugrevelio,项目名称:thefuck,代码行数:29,代码来源:shell_logger.py
示例2: spawn
def spawn(self, argv=None):
'''
Create a spawned process.
Based on the code for pty.spawn().
'''
assert self.master_fd is None
if not argv:
argv = [os.environ['SHELL']]
pid, master_fd = pty.fork()
self.master_fd = master_fd
if pid == pty.CHILD:
os.execlp(argv[0], *argv)
old_handler = signal.signal(signal.SIGWINCH, self._signal_winch)
try:
mode = tty.tcgetattr(pty.STDIN_FILENO)
tty.setraw(pty.STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
self._init_fd()
try:
self._copy()
except (IOError, OSError):
if restore:
tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(master_fd)
self.master_fd = None
signal.signal(signal.SIGWINCH, old_handler)
self._set_pty_size()
开发者ID:mpobrien,项目名称:teaminal,代码行数:32,代码来源:ptyintercept.py
示例3: enter
def enter(self):
if self.in_raw_mode:
return
fd = sys.stdin.fileno()
try:
old = tty.tcgetattr(fd)
new = old[:]
self.saved_mode = old
except:
log.msg('not a typewriter!')
self.saved_mode = None
return
# iflage
new[0] = new[0] | tty.IGNPAR
new[0] = new[0] & ~(tty.ISTRIP|tty.INLCR|tty.IGNCR|tty.ICRNL |
tty.IXON | tty.IXANY | tty.IXOFF)
if hasattr(tty, 'IUCLC'):
new[0] = new[0] & ~tty.IUCLC
# lflag
new[3] = new[3] & ~(tty.ISIG | tty.ICANON | tty.ECHO | tty.ECHO |
tty.ECHOE | tty.ECHOK | tty.ECHONL)
if hasattr(tty, 'IEXTEN'):
new[3] = new[3] & ~tty.IEXTEN
#oflag
new[1] = new[1] & ~tty.OPOST
new[6][tty.VMIN] = 1
new[6][tty.VTIME] = 0
tty.tcsetattr(fd, tty.TCSANOW, new)
self.in_raw_mode = True
开发者ID:orangle,项目名称:CodeHouse,代码行数:35,代码来源:sshclient.py
示例4: read_chr
def read_chr():
old_settings = tty.tcgetattr(sys.stdin.fileno())
tty.setraw(sys.stdin, tty.TCSANOW)
chr = sys.stdin.read(1)
tty.tcsetattr(sys.stdin.fileno(), tty.TCSADRAIN, old_settings)
return chr
开发者ID:chromakode,项目名称:conductor,代码行数:7,代码来源:utils.py
示例5: menu
def menu(self, title, names, top_info=(), cmds=None):
attr = tty.tcgetattr(sys.stdin)
try:
self.cprint(TITLE, "==>", title)
items = {}
for i in top_info:
self.cprint(b"34", " ", i)
for c, (n, t) in letterify(names):
print(" ", c, t)
items[c] = n
if cmds:
mlen = max(len(mv) + len(k) for k, mv, name in cmds) + 1
for k, mv, name in cmds:
print(" :{0:{1}} {2}".format(k + " " + mv, mlen, name))
tty.setcbreak(sys.stdin)
ch = sys.stdin.read(1)
if ch == ":":
tty.tcsetattr(sys.stdin, tty.TCSADRAIN, attr)
cmd = input(":")
parts = cmd.strip().split(None, 1)
if not parts:
return None
raise CommandExecute(*parts)
elif ch in items:
return items[ch]
finally:
tty.tcsetattr(sys.stdin, tty.TCSADRAIN, attr)
开发者ID:tailhook,项目名称:pacmajor,代码行数:27,代码来源:display.py
示例6: _leaveRawMode
def _leaveRawMode():
global _inRawMode
if not _inRawMode:
return
fd = sys.stdin.fileno()
tty.tcsetattr(fd, tty.TCSANOW, _savedRawMode)
_inRawMode = 0
开发者ID:BarnetteME1,项目名称:indeed_scraper,代码行数:7,代码来源:conch.py
示例7: _copy
def _copy(master_fd, master_read=_read, stdin_read=_read, stdin_fd=STDIN_FILENO,
stdout_fd=STDOUT_FILENO):
"""Parent copy loop.
Copies
pty master -> stdout_fd (master_read)
stdin_fd -> pty master (stdin_read)"""
try:
mode = tty.tcgetattr(stdin_fd)
tty.setraw(stdin_fd)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
try:
while 1:
rfds, wfds, xfds = select(
[master_fd, stdin_fd], [], [])
if master_fd in rfds:
data = master_read(master_fd)
os.write(stdout_fd, data)
if stdin_fd in rfds:
data = stdin_read(stdin_fd)
_writen(master_fd, data)
except (IOError, OSError, error): # The last entry is select.error
if restore:
tty.tcsetattr(stdin_fd, tty.TCSAFLUSH, mode)
if stdin_fd > STDERR_FILENO:
os.close(stdin_fd)
if stdout_fd > STDERR_FILENO:
os.close(stdout_fd)
开发者ID:3van,项目名称:pbis,代码行数:29,代码来源:ptyext.py
示例8: _connectSSHLocal
def _connectSSHLocal(self, hostname, username, passwd):
sshcmd = [self.ssh_bin, '%[email protected]%s' % (username, hostname)]
if self.ssh_extraopt:
sshcmd += self.ssh_extraopt.split()
self.addStringToClipboard(passwd)
pid, self.remote_fd = pty.fork()
if pid == pty.CHILD:
os.execlp(sshcmd[0], *sshcmd)
try:
mode = tty.tcgetattr(pty.STDIN_FILENO)
tty.setraw(pty.STDIN_FILENO)
restore = True
except tty.error:
restore = False
signal.signal(signal.SIGWINCH, self._winchHandler)
self._setRemoteTTYSize(self.remote_fd)
self._setTerminalTitle('%[email protected]%s' % (username, hostname))
try:
self._copySSHData(self.remote_fd, passwd)
except (IOError, OSError):
pass
except:
if restore:
tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode)
raise
if restore:
tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode)
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
os.close(self.remote_fd)
开发者ID:sii,项目名称:siptrack,代码行数:29,代码来源:cmdconnect.py
示例9: setup
def setup(self):
if tty:
self.tcattr = tty.tcgetattr(sys.stdin.fileno())
tcattr = tty.tcgetattr(sys.stdin.fileno())
tcattr[0] = tcattr[0] & ~(tty.IXON)
tty.tcsetattr(sys.stdin.fileno(), tty.TCSANOW, tcattr)
self.w = curses.initscr()
curses.cbreak()
curses.noecho()
try: curses.meta(1)
except: pass
self.cursor(0)
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
signal.signal(signal.SIGHUP, self.handler_quit)
signal.signal(signal.SIGINT, self.handler_quit)
signal.signal(signal.SIGTERM, self.handler_quit)
signal.signal(signal.SIGWINCH, self.handler_resize)
self.win_root = RootWindow(None)
self.win_root.update()
self.win_status = self.win_root.win_status
self.status = self.win_status.status
self.win_podlist = self.win_root.win_tab.win_podlist
self.timeout = Timeout()
开发者ID:BackupTheBerlios,项目名称:orm-svn,代码行数:27,代码来源:norm.py
示例10: spawn
def spawn(argv, master_read=_read, stdin_read=_read):
"""Create a spawned process."""
if type(argv) == type(''):
argv = (argv,)
pid, master_fd = fork()
if pid == CHILD:
try:
os.execlp(argv[0], *argv)
except:
# If we wanted to be really clever, we would use
# the same method as subprocess() to pass the error
# back to the parent. For now just dump stack trace.
traceback.print_exc()
finally:
os._exit(1)
try:
mode = tty.tcgetattr(STDIN_FILENO)
tty.setraw(STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
try:
_copy(master_fd, master_read, stdin_read)
except OSError:
# Some OSes never return an EOF on pty, just raise
# an error instead.
pass
finally:
if restore:
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(master_fd)
return os.waitpid(pid, 0)[1]
开发者ID:freenas,项目名称:py-bsd,代码行数:33,代码来源:pty.py
示例11: __init__
def __init__(self, filename):
SerialIO.__init__(self, filename)
self.fd = os.open(filename, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
tty.setraw(self.fd)
attr = tty.tcgetattr(self.fd)
attr[tty.ISPEED] = attr[tty.OSPEED] = tty.B57600
tty.tcsetattr(self.fd, tty.TCSAFLUSH, attr)
开发者ID:twpayne,项目名称:flytecfs,代码行数:7,代码来源:flytecdevice.py
示例12: spawn
def spawn(argv, master_read=pty._read, stdin_read=pty._read, handle_window_size=False):
# copied from pty.py, with modifications
# note that it references a few private functions - would be nice to not
# do that, but you know
if type(argv) == type(''):
argv = (argv,)
pid, master_fd, slave_name = fork(handle_window_size)
if pid == CHILD:
os.execlp(argv[0], *argv)
try:
mode = tty.tcgetattr(STDIN_FILENO)
tty.setraw(STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
if handle_window_size:
signal.signal(
signal.SIGWINCH,
lambda signum, frame: _winch(slave_name, pid)
)
while True:
try:
pty._copy(master_fd, master_read, stdin_read)
except OSError as e:
if e.errno == errno.EINTR:
continue
if restore:
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
break
os.close(master_fd)
return os.waitpid(pid, 0)[1]
开发者ID:thomasballinger,项目名称:python-termcast-client,代码行数:34,代码来源:pity.py
示例13: pty_spawn
def pty_spawn(argv):
"""Version of pty.spawn() for PY2, that returns the exit code.
This works around https://bugs.python.org/issue2489.
"""
logger.info("Using builtin pty.spawn()")
import pty
import tty
if isinstance(argv, bytes):
argv = (argv,)
pid, master_fd = pty.fork()
if pid == pty.CHILD:
os.execlp(argv[0], *argv)
try:
mode = tty.tcgetattr(pty.STDIN_FILENO)
tty.setraw(pty.STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
try:
pty._copy(master_fd, pty._read, pty._read)
except (IOError, OSError):
if restore:
tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(master_fd)
return os.waitpid(pid, 0)[1]
开发者ID:ViDA-NYU,项目名称:reprozip,代码行数:29,代码来源:misc.py
示例14: _enterRawMode
def _enterRawMode():
global _inRawMode, _savedRawMode
if _inRawMode:
return
fd = sys.stdin.fileno()
try:
old = tty.tcgetattr(fd)
new = old[:]
except:
log.msg('not a typewriter!')
else:
# iflage
new[0] = new[0] | tty.IGNPAR
new[0] = new[0] & ~(tty.ISTRIP | tty.INLCR | tty.IGNCR | tty.ICRNL |
tty.IXON | tty.IXANY | tty.IXOFF)
if hasattr(tty, 'IUCLC'):
new[0] = new[0] & ~tty.IUCLC
# lflag
new[3] = new[3] & ~(tty.ISIG | tty.ICANON | tty.ECHO | tty.ECHO |
tty.ECHOE | tty.ECHOK | tty.ECHONL)
if hasattr(tty, 'IEXTEN'):
new[3] = new[3] & ~tty.IEXTEN
#oflag
new[1] = new[1] & ~tty.OPOST
new[6][tty.VMIN] = 1
new[6][tty.VTIME] = 0
_savedRawMode = old
tty.tcsetattr(fd, tty.TCSANOW, new)
#tty.setraw(fd)
_inRawMode = 1
开发者ID:BarnetteME1,项目名称:indeed_scraper,代码行数:34,代码来源:conch.py
示例15: setup_tty_for_pty
def setup_tty_for_pty(func):
"""
Sets up tty for raw mode while retaining original tty settings and then
starts the reactor to connect to the pty. Upon exiting pty, restores
original tty settings.
:param func:
The callable to run after the tty is ready, such as ``reactor.run``
"""
# Preserve original tty settings
stdin_fileno = sys.stdin.fileno()
old_ttyattr = tty.tcgetattr(stdin_fileno)
try:
# Enter raw mode on the local tty.
tty.setraw(stdin_fileno)
raw_ta = tty.tcgetattr(stdin_fileno)
raw_ta[tty.LFLAG] |= tty.ISIG
raw_ta[tty.OFLAG] |= tty.OPOST | tty.ONLCR
# Pass ^C through so we can abort traceroute, etc.
raw_ta[tty.CC][tty.VINTR] = '\x18' # ^X is the new ^C
# Ctrl-Z is used by a lot of vendors to exit config mode
raw_ta[tty.CC][tty.VSUSP] = 0 # disable ^Z
tty.tcsetattr(stdin_fileno, tty.TCSANOW, raw_ta)
# Execute our callable here
func()
finally:
# Restore original tty settings
tty.tcsetattr(stdin_fileno, tty.TCSANOW, old_ttyattr)
开发者ID:altoplano,项目名称:trigger,代码行数:33,代码来源:cli.py
示例16: setModes
def setModes(self):
pty = self.pty
attr = tty.tcgetattr(pty.fileno())
for mode, modeValue in self.modes:
if mode not in ttymodes.TTYMODES:
continue
ttyMode = ttymodes.TTYMODES[mode]
if len(ttyMode) == 2: # Flag.
flag, ttyAttr = ttyMode
if not hasattr(tty, ttyAttr):
continue
ttyval = getattr(tty, ttyAttr)
if modeValue:
attr[flag] = attr[flag] | ttyval
else:
attr[flag] = attr[flag] & ~ttyval
elif ttyMode == 'OSPEED':
attr[tty.OSPEED] = getattr(tty, 'B%s' % (modeValue,))
elif ttyMode == 'ISPEED':
attr[tty.ISPEED] = getattr(tty, 'B%s' % (modeValue,))
else:
if not hasattr(tty, ttyMode):
continue
ttyval = getattr(tty, ttyMode)
attr[tty.CC][ttyval] = chr(modeValue)
tty.tcsetattr(pty.fileno(), tty.TCSANOW, attr)
开发者ID:BarnetteME1,项目名称:indeed_scraper,代码行数:26,代码来源:unix.py
示例17: _spawn
def _spawn(self):
'''Create a spawned process.
Based on pty.spawn() from standard library.
'''
assert self.master_fd is None
pid, self.master_fd = pty.fork()
if pid == pty.CHILD:
os.execlp(self.command[0], *self.command)
old_handler = signal.signal(signal.SIGWINCH, self._signal_winch)
try:
mode = tty.tcgetattr(pty.STDIN_FILENO)
tty.setraw(pty.STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
self._set_pty_size()
try:
self._copy()
except (IOError, OSError):
if restore:
tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(self.master_fd)
self.master_fd = None
signal.signal(signal.SIGWINCH, old_handler)
return True
开发者ID:asciimoo,项目名称:ipty,代码行数:35,代码来源:ipty.py
示例18: spawn
def spawn(argv, master_read=pty_read, stdin_read=pty_read):
"""Create a spawned process.
Based on pty.spawn code."""
# TODO(larsbutler): This type check won't work with python3
# See http://packages.python.org/six/#six.string_types
# for a possible solution.
if isinstance(argv, (basestring)):
argv = (argv,)
pid, master_fd = pty.fork()
if pid == pty.CHILD:
os.execlp(argv[0], *argv)
try:
mode = tty.tcgetattr(pty.STDIN_FILENO)
tty.setraw(pty.STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
# get pseudo-terminal window size
buf = array.array('h', [0, 0, 0, 0])
fcntl.ioctl(pty.STDOUT_FILENO, termios.TIOCGWINSZ, buf, True)
# pass window size settings to forked one
fcntl.ioctl(master_fd, termios.TIOCSWINSZ, buf)
try:
pty_copy(master_fd, master_read, stdin_read)
except (IOError, OSError):
if restore:
tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(master_fd)
开发者ID:pkit,项目名称:zerovm-cli,代码行数:29,代码来源:zvsh.py
示例19: _detach
def _detach(self):
"""Dettach the controlling terminal to aptdaemon."""
for wid in self._watchers:
GLib.source_remove(wid)
if self._old_tty_mode:
tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH,
self._old_tty_mode)
开发者ID:pombredanne,项目名称:linuxtrail,代码行数:7,代码来源:console.py
示例20: interact
def interact(fd, stderr=None):
"""Interact with pty"""
## window size change handler
debug("started")
def change_winsz(signum, frame):
winsz_arg = struct.pack("HHHH", 0, 0, 0, 0)
fcntl.ioctl(fd, termios.TIOCSWINSZ,
fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, winsz_arg))
old_handler = signal.signal(signal.SIGWINCH, change_winsz)
try:
mode = termios.tcgetattr(sys.stdin)
tty.setraw(sys.stdin, termios.TCSANOW)
restore = 1
except tty.error:
restore = 0
debug("stdin: %s" % sys.stdin.fileno())
debug("child tty: %s" % fd)
fds = [fd, sys.stdin.fileno()]
if stderr:
fds.append(stderr)
debug("child stderr: %s" % stderr)
debug("before loop")
try:
try:
while True:
if not fds:
break
try:
rfds, wfds, xfds = select.select(fds, [], [])
except select.error, se:
if se[0] == errno.EINTR:
continue # Interrupted system call
else:
raise se
for i, o in [[fd, sys.stdout.fileno()],
[stderr, sys.stderr.fileno()],
[sys.stdin.fileno(), fd]]:
if i in rfds:
debug("about to read from %s" % i)
data = os.read(i, 1024)
if not data: # Reached EOF.
fds.remove(i)
debug('EOF %s' % i)
else:
debug('read from %s: %s' % (i, repr(data)))
write(o, data)
except (IOError, OSError), e:
exc_type, exc_obj, exc_tb = sys.exc_info()
debug("IOError/OSError %s: %s" % (traceback.format_exception_only(exc_type, exc_obj)[0],
traceback.format_tb(exc_tb)))
pass
finally:
debug("finished")
if restore:
tty.tcsetattr(sys.stdin, tty.TCSAFLUSH, mode)
signal.signal(signal.SIGWINCH, old_handler)
os.close(fd)
if stderr:
os.close(stderr)
开发者ID:alexnsl,项目名称:hwswa2,代码行数:59,代码来源:serverd.py
注:本文中的tty.tcsetattr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论