本文整理汇总了Python中tty.tcgetattr函数的典型用法代码示例。如果您正苦于以下问题:Python tcgetattr函数的具体用法?Python tcgetattr怎么用?Python tcgetattr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tcgetattr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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
示例3: join_term
def join_term(self):
out('Successfully joined %s' % (self.room_url()))
self.orig_stdout_atts = tty.tcgetattr(sys.stdout)
stdout = sys.stdout.fileno()
tty.setraw(stdout)
fl = fcntl.fcntl(stdout, fcntl.F_GETFL)
fcntl.fcntl(stdout, fcntl.F_SETFL, fl | os.O_NONBLOCK)
self.orig_stdin_atts = tty.tcgetattr(sys.stdin)
stdin = sys.stdin.fileno()
tty.setraw(stdin)
fl = fcntl.fcntl(stdin, fcntl.F_GETFL)
fcntl.fcntl(stdin, fcntl.F_SETFL, fl | os.O_NONBLOCK)
def ship_stdin(fd):
data = read(fd)
if data:
self.transport("term_stdin", {'data': data, 'id': self.term_id})
if 'term_stdin' in self.ri['perms']:
out('You have permission to write to this terminal. Remember: With great power comes great responsibility.')
self.add_fd(stdin, reader=ship_stdin, name='join_term_stdin')
else:
out('You do not have permission to write to this terminal.')
def stdout_write(buf):
write(stdout, buf.encode('utf-8'))
self.handle_stdio = stdout_write
self._set_pty_size(self.ri['terms'][str(self.term_id)]['size'])
开发者ID:pombredanne,项目名称:flootty,代码行数:30,代码来源:flootty.py
示例4: __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
示例5: __enter__
def __enter__(self):
try:
self.mode = tty.tcgetattr(self.fd)
tty.setraw(self.fd)
self.restore = True
except tty.error: # This is the same as termios.error
pass
开发者ID:lichen19844,项目名称:asciinema,代码行数:7,代码来源:term.py
示例6: 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
示例7: posix_shell
def posix_shell(chan,logfile):
import select
oldtty = termios.tcgetattr(sys.stdin)
f=open(logfile,'w')
try:
mode = tty.tcgetattr(sys.stdin.fileno())
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
chan.settimeout(0.0)
while True:
r, w, e = select.select([chan, sys.stdin], [], [])
if chan in r:
try:
x = chan.recv(1024)
if len(x) == 0:
sys.stdout.write('\r\n*** EOF\r\n')
break
sys.stdout.write(x)
sys.stdout.flush()
f.write(x)
f.flush()
except socket.timeout:
pass
if sys.stdin in r:
#x = sys.stdin.read(1)
x=os.read(sys.stdin.fileno(),1000)
if len(x) == 0:
break
chan.send(x)
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
f.close()
开发者ID:yuzh,项目名称:mylogin,代码行数:35,代码来源:mylogin.py
示例8: 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
示例9: 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
示例10: 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
示例11: _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
示例12: _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
示例13: _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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: _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
示例19: 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
示例20: _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
注:本文中的tty.tcgetattr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论