mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-14 11:57:44 +00:00
Assume isatty is always defined, and catch AttributeError. Also don't bother checking colour==Normal
This commit is contained in:
parent
1af16acd4c
commit
a5aea15a6b
1 changed files with 6 additions and 2 deletions
8
synctl
8
synctl
|
@ -50,10 +50,14 @@ def pid_running(pid):
|
|||
def write(message, colour=NORMAL, stream=sys.stdout):
|
||||
# Lets check if we're writing to a TTY before colouring
|
||||
should_colour = False
|
||||
if stream in (sys.stdout, sys.stderr):
|
||||
try:
|
||||
should_colour = stream.isatty()
|
||||
except AttributeError:
|
||||
# Just in case `isatty` isn't defined on everything. The python
|
||||
# docs are incredibly vague.
|
||||
pass
|
||||
|
||||
if not should_colour or colour == NORMAL:
|
||||
if not should_colour:
|
||||
stream.write(message + "\n")
|
||||
else:
|
||||
stream.write(colour + message + NORMAL + "\n")
|
||||
|
|
Loading…
Reference in a new issue