summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2018-10-18 10:51:14 +0100
committerGitHub <noreply@github.com>2018-10-18 10:51:14 +0100
commite77f24d80ac1fd8afc27808bc5db1ef053af51f8 (patch)
tree8412e84c9f69270a87a6fe0b8af202174e59a8ac
parentMerge pull request #4050 from matrix-org/erikj/fix_py37_iteration (diff)
parentAssume isatty is always defined, and catch AttributeError. Also don't bother ... (diff)
downloadsynapse-e77f24d80ac1fd8afc27808bc5db1ef053af51f8.tar.xz
Merge pull request #4049 from matrix-org/erikj/synctl_colour
Only colourise synctl output when attached to tty
-rw-r--r--changelog.d/4049.misc1
-rwxr-xr-xsynctl11
2 files changed, 11 insertions, 1 deletions
diff --git a/changelog.d/4049.misc b/changelog.d/4049.misc
new file mode 100644
index 0000000000..4370d9dfa6
--- /dev/null
+++ b/changelog.d/4049.misc
@@ -0,0 +1 @@
+Only colourise synctl output when attached to tty
diff --git a/synctl b/synctl
index 09b64459b1..4bd4c68b37 100755
--- a/synctl
+++ b/synctl
@@ -48,7 +48,16 @@ def pid_running(pid):
 
 
 def write(message, colour=NORMAL, stream=sys.stdout):
-    if colour == NORMAL:
+    # Lets check if we're writing to a TTY before colouring
+    should_colour = False
+    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:
         stream.write(message + "\n")
     else:
         stream.write(colour + message + NORMAL + "\n")