mailr15762 - in /1.3: prompt/base_class.py relax_errors.py relax_warnings.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on April 17, 2012 - 16:50:
Author: bugman
Date: Tue Apr 17 16:50:34 2012
New Revision: 15762

URL: http://svn.gna.org/viewcvs/relax?rev=15762&view=rev
Log:
The sys.std*.isatty() methods are now being used to determine if text output 
should be coloured.

This removes the need for the status.text_colouring flag, and can handle 
changes in IO redirection
occurring at any point.  This was suggested at both
http://mail.python.org/pipermail/python-list/2012-April/1291046.html and
http://mail.python.org/pipermail/python-list/2012-April/1291048.html.


Modified:
    1.3/prompt/base_class.py
    1.3/relax_errors.py
    1.3/relax_warnings.py

Modified: 1.3/prompt/base_class.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/base_class.py?rev=15762&r1=15761&r2=15762&view=diff
==============================================================================
--- 1.3/prompt/base_class.py (original)
+++ 1.3/prompt/base_class.py Tue Apr 17 16:50:34 2012
@@ -26,6 +26,7 @@
 # Python module imports.
 import platform
 from re import split
+import sys
 from textwrap import wrap
 
 # relax module imports.
@@ -225,7 +226,7 @@
         self.ps3 = '\n%s' % self.ps1
 
         # Coloured text.
-        if status.text_colouring:
+        if sys.stdout.isatty():
             self.ps1 = "\033[94m%s\033[0m" % self.ps1
             self.ps2 = "\033[94m%s\033[0m" % self.ps2
             self.ps3 = "\n\033[94m%s\033[0m" % self.ps1

Modified: 1.3/relax_errors.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/relax_errors.py?rev=15762&r1=15761&r2=15762&view=diff
==============================================================================
--- 1.3/relax_errors.py (original)
+++ 1.3/relax_errors.py Tue Apr 17 16:50:34 2012
@@ -32,7 +32,7 @@
     bz2 = False
 from cPickle import dump
 from re import match
-from sys import stderr
+import sys
 import time
 from types import ClassType
 
@@ -77,10 +77,10 @@
 
     # Open the file for writing.
     if bz2:
-        stderr.write("\n\nStoring the relax state in the file 
'%s.bz2'.\n\n\n" % file_name)
+        sys.stderr.write("\n\nStoring the relax state in the file 
'%s.bz2'.\n\n\n" % file_name)
         file = BZ2File(file_name+'.bz2', 'w')
     else:
-        stderr.write("\n\nStoring the relax state in the file '%s'.\n\n\n" % 
file_name)
+        sys.stderr.write("\n\nStoring the relax state in the file 
'%s'.\n\n\n" % file_name)
         file = open(file_name, 'w')
 
     # Pickle the data class and write it to file
@@ -104,8 +104,8 @@
         if status.pedantic:
             save_state()
 
-        # Modify the error message to include 'RelaxError' at the start.
-        if status.text_colouring:
+        # Modify the error message to include 'RelaxError' at the start 
(using coloured text if a TTY).
+        if sys.stderr.isatty():
             return ("\033[31mRelaxError: " + self.text + "\033[0m\n")
         else:
             return ("RelaxError: " + self.text + "\n")

Modified: 1.3/relax_warnings.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/relax_warnings.py?rev=15762&r1=15761&r2=15762&view=diff
==============================================================================
--- 1.3/relax_warnings.py (original)
+++ 1.3/relax_warnings.py Tue Apr 17 16:50:34 2012
@@ -25,6 +25,7 @@
 
 # Python module imports.
 import inspect
+import sys
 import warnings
 
 # relax module imports.
@@ -57,7 +58,7 @@
         message = tb + message
 
     # Text colouring
-    if status.text_colouring:
+    if sys.stderr.isatty():
         message = "\033[33m%s\033[0m" % message
 
     # Return the warning message.




Related Messages


Powered by MHonArc, Updated Tue Apr 17 17:20:01 2012