def __init__(self, app, no_color=False, **kwargs): self.app = app self._init_manager(app, **kwargs) if not isatty(self.stdout): no_color = True self.colored = colored(enabled=not no_color) self.init_groups()
def supports_color(self, colorize=None, logfile=None): colorize = self.colorize if colorize is None else colorize if self.app.IS_WINDOWS: # Windows does not support ANSI color codes. return False if colorize or colorize is None: # Only use color if there's no active log file # and stderr is an actual terminal. return logfile is None and isatty(sys.stderr) return colorize
def on_after_init(self, purge=False, no_color=None, redirect_stdouts=None, redirect_stdouts_level=None, **kwargs): self.redirect_stdouts = self.app.either( 'worker_redirect_stdouts', redirect_stdouts) self.redirect_stdouts_level = self.app.either( 'worker_redirect_stdouts_level', redirect_stdouts_level) super(Worker, self).setup_defaults(**kwargs) self.purge = purge self.no_color = no_color self._isatty = isatty(sys.stdout) self.colored = self.app.log.colored( self.logfile, enabled=not no_color if no_color is not None else no_color )
def test_isatty(): fh = Mock(name='fh') assert isatty(fh) is fh.isatty() fh.isatty.side_effect = AttributeError() assert not isatty(fh)
def colored(self): if self._colored is None: self._colored = term.colored( enabled=isatty(self.stdout) and not self.no_color) return self._colored
def supports_images(): return isatty(sys.stdin) and ITERM_PROFILE
def colored(self): if self._colored is None: self._colored = term.colored(enabled=isatty(self.stdout) and not self.no_color) return self._colored
def _term_supports_images(self): return isatty(sys.stdin) and os.environ.get('ITERM_PROFILE')
def test_tty(self): fh = Mock(name='fh') self.assertIs(isatty(fh), fh.isatty()) fh.isatty.side_effect = AttributeError() self.assertFalse(isatty(fh))