Here are the examples of the python api sys.__stdout__.isatty taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
6 Examples
3
Example 1
def init(color=ColorMode['auto']):
"""Disables pre-initialized coloring if never mode specified or stdout is a tty.
:param color: the color mode to use, defaults to auto"""
# TODO: fix tty detection
if color == ColorMode['never'] \
or not res \
or (color == ColorMode['auto'] and not sys.__stdout__.isatty()):
global get_adfixes, color_path, color_status, seq_tpl, nor_fmt
get_adfixes = lambda _: ('', '')
color_path = lambda x: x
color_status = lambda x: x[0]
seq_tpl = '%s'
nor_fmt = '%s'
3
Example 2
def test_main():
if not sys.__stdout__.isatty():
raise unittest.SkipTest("sys.__stdout__ is not a tty")
# testing setupterm() inside initscr/endwin
# causes terminal breakage
curses.setupterm(fd=sys.__stdout__.fileno())
try:
stdscr = curses.initscr()
main(stdscr)
finally:
curses.endwin()
unit_tests()
3
Example 3
Project: portage-funtoo Source File: BinpkgFetcher.py
def _pipe(self, fd_pipes):
"""When appropriate, use a pty so that fetcher progress bars,
like wget has, will work properly."""
if self.background or not sys.__stdout__.isatty():
# When the output only goes to a log file,
# there's no point in creating a pty.
return os.pipe()
stdout_pipe = None
if not self.background:
stdout_pipe = fd_pipes.get(1)
got_pty, master_fd, slave_fd = \
_create_pty_or_pipe(copy_term_size=stdout_pipe)
return (master_fd, slave_fd)
3
Example 4
Project: smoker Source File: console.py
def is_interactive_shell():
"""
Try to guess if current shell is interactive
Return bool
"""
return sys.__stdout__.isatty()
2
Example 5
Project: broc Source File: Log.py
def colorprint(color, msg, prefix=True):
"""
print message with color
"""
if prefix:
now = "[" + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) \
+ " " + str(threading.current_thread().ident) + "] "
else:
now = ""
global console_lock
console_lock.acquire()
try:
if color == "RED":
if (sys.__stdout__.isatty()):
print "\033[31m%s%s\033[0m" % (now, msg)
else:
print "%s%s" % (now, msg)
sys.stdout.flush()
return
if color == "GREEN":
if (sys.__stdout__.isatty()):
print "\033[32m%s%s\033[0m" % (now, msg)
else:
print "%s%s" % (now, msg)
sys.stdout.flush()
return
if color == "YELLOW":
if (sys.__stdout__.isatty()):
print "\033[33m%s%s\033[0m" % (now, msg)
else:
print "%s%s" % (now, msg)
sys.stdout.flush()
return
if color == "BLUE":
if (sys.__stdout__.isatty()):
print "\033[34m%s%s\033[0m" % (now, msg)
else:
print "%s%s" % (now, msg)
sys.stdout.flush()
return
print "%s%s" % (now, msg)
sys.stdout.flush()
finally:
console_lock.release()
0
Example 6
Project: crossbar Source File: cli.py
def _startlog(options, reactor):
"""
Start the logging in a way that all the subcommands can use it.
"""
loglevel = getattr(options, "loglevel", "info")
logformat = getattr(options, "logformat", "none")
colour = getattr(options, "colour", "auto")
set_global_log_level(loglevel)
# The log observers (things that print to stderr, file, etc)
observers = []
if getattr(options, "logtofile", False):
# We want to log to a file
if not options.logdir:
logdir = options.cbdir
else:
logdir = options.logdir
logfile = os.path.join(logdir, "node.log")
if loglevel in ["error", "warn", "info"]:
show_source = False
else:
show_source = True
observers.append(make_logfile_observer(logfile, show_source))
else:
# We want to log to stdout/stderr.
if colour == "auto":
if sys.__stdout__.isatty():
colour = True
else:
colour = False
elif colour == "true":
colour = True
else:
colour = False
if loglevel == "none":
# Do no logging!
pass
elif loglevel in ["error", "warn", "info"]:
# Print info to stdout, warn+ to stderr
observers.append(make_stdout_observer(show_source=False,
format=logformat,
colour=colour))
observers.append(make_stderr_observer(show_source=False,
format=logformat,
colour=colour))
elif loglevel == "debug":
# Print debug+info to stdout, warn+ to stderr, with the class
# source
observers.append(make_stdout_observer(show_source=True,
levels=(LogLevel.info,
LogLevel.debug),
format=logformat,
colour=colour))
observers.append(make_stderr_observer(show_source=True,
format=logformat,
colour=colour))
elif loglevel == "trace":
# Print trace+, with the class source
observers.append(make_stdout_observer(show_source=True,
levels=(LogLevel.info,
LogLevel.debug),
format=logformat,
trace=True,
colour=colour))
observers.append(make_stderr_observer(show_source=True,
format=logformat,
colour=colour))
else:
assert False, "Shouldn't ever get here."
for observer in observers:
globalLogPublisher.addObserver(observer)
# Make sure that it goes away
reactor.addSystemEventTrigger('after', 'shutdown',
globalLogPublisher.removeObserver, observer)
# Actually start the logger.
start_logging(None, loglevel)