mailr3043 - in /branches/error_import: relax warnings.py


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

Header


Content

Posted by edward on February 27, 2007 - 06:07:
Author: bugman
Date: Tue Feb 27 06:06:50 2007
New Revision: 3043

URL: http://svn.gna.org/viewcvs/relax?rev=3043&view=rev
Log:
Removed the nesting of the RelaxWarnings and added the global variables 
Debug, Pedantic, and relax.


Modified:
    branches/error_import/relax
    branches/error_import/warnings.py

Modified: branches/error_import/relax
URL: 
http://svn.gna.org/viewcvs/relax/branches/error_import/relax?rev=3043&r1=3042&r2=3043&view=diff
==============================================================================
--- branches/error_import/relax (original)
+++ branches/error_import/relax Tue Feb 27 06:06:50 2007
@@ -137,6 +137,7 @@
         errors.Debug = self.Debug
         errors.relax = self
         warnings.Debug = self.Debug
+        warnings.Pedantic = self.Pedantic
         warnings.relax = self
 
         # Show the version number and exit.

Modified: branches/error_import/warnings.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/error_import/warnings.py?rev=3043&r1=3042&r2=3043&view=diff
==============================================================================
--- branches/error_import/warnings.py (original)
+++ branches/error_import/warnings.py Tue Feb 27 06:06:50 2007
@@ -20,110 +20,90 @@
 #                                                                            
 #
 
###############################################################################
 
-import __builtin__
-from re import match
-from types import ClassType
 import warnings
 import inspect
 
+from errors import BaseError
 
 
-# The RelaxWarning system.
-##########################
-
-class RelaxWarnings:
-    def __init__(self):
-        """Class for placing all the warnings below into __builtin__"""
-
-        # Loop over all objects in 'self'.
-        for name in dir(self):
-            # Get the object.
-            object = getattr(self, name)
-
-            # Skip over all non-warning class objects.
-            if type(object) != ClassType or not match('Relax', name):
-                continue
-
-            # Place the warnings into __builtin__
-            __builtin__.__setattr__(name, object)
-
-            # Tuple of all the warnings.
-            if hasattr(__builtin__, 'AllRelaxWarnings'):
-                __builtin__.AllRelaxWarnings = __builtin__.AllRelaxWarnings, 
object
-            else:
-                __builtin__.AllRelaxWarnings = object,
-
-        # Format warning messages.
-        warnings.formatwarning = self.format
-
-        # Set warning filters.
-        if Pedantic:
-            warnings.filterwarnings('error', category=self.BaseWarning)
-        else:
-            warnings.filterwarnings('always', category=self.BaseWarning)
+# Global variables.
+relax = None
+Debug = False
+Pedantic = False
 
 
-    def format(self, message, category, filename, lineno):
-        """ Replacement for warnings.formatwarning to customise output 
format."""
+# Format warning messages.
+warnings.formatwarning = format
 
-        # Add the text 'RelaxWarning: ' to the start of the warning message.
-        if issubclass(category, self.BaseWarning):
-            message = "RelaxWarning: %s\n\n" % message
-
-        # Print stack-trace in debug mode.
-        if Debug:
-            tb = ""
-            for frame in inspect.stack()[4:]:
-                file = frame[1]
-                lineNo = frame[2]
-                func = frame[3]
-                tb_frame = '  File "%s", line %i, in %s\n' % (file, lineNo, 
func)
-                try:
-                    context = frame[4][frame[5]]
-                except TypeError:
-                    pass
-                else:
-                    tb_frame = '%s    %s\n' % (tb_frame, context.strip())
-                tb = tb_frame + tb
-            tb = "Traceback (most recent call last):\n%s" % tb
-            message = tb + message
-
-        # Return the warning message.
-        return message
+# Set warning filters.
+if Pedantic:
+    warnings.filterwarnings('error', category=BaseWarning)
+else:
+    warnings.filterwarnings('always', category=BaseWarning)
 
 
-    # Base class for all warnings.
-    ##############################
+# The warning formatting function.
+def format(message, category, filename, lineno):
+    """ Replacement for warnings.formatwarning to customise output format."""
 
-    class BaseWarning(Warning, RelaxErrors.BaseError):
-        def __str__(self):
-            return self.text
+    # Add the text 'RelaxWarning: ' to the start of the warning message.
+    if issubclass(category, BaseWarning):
+        message = "RelaxWarning: %s\n\n" % message
+
+    # Print stack-trace in debug mode.
+    if Debug:
+        tb = ""
+        for frame in inspect.stack()[4:]:
+            file = frame[1]
+            lineNo = frame[2]
+            func = frame[3]
+            tb_frame = '  File "%s", line %i, in %s\n' % (file, lineNo, func)
+            try:
+                context = frame[4][frame[5]]
+            except TypeError:
+                pass
+            else:
+                tb_frame = '%s    %s\n' % (tb_frame, context.strip())
+            tb = tb_frame + tb
+        tb = "Traceback (most recent call last):\n%s" % tb
+        message = tb + message
+
+    # Return the warning message.
+    return message
 
 
-    # Standard warnings.
-    ####################
+# Base class for all warnings.
+##############################
 
-    class RelaxWarning(BaseWarning):
-        def __init__(self, text):
-            self.text = text
+class BaseWarning(Warning, BaseError):
+    def __str__(self):
+        return self.text
 
 
-    # PDB warnings.
-    ###############
+# Standard warnings.
+####################
 
-    # Zero length XH bond vector.
-    class RelaxZeroVectorWarning(BaseWarning):
-        def __init__(self, res):
-            self.text = "The XH bond vector for residue " + `res` + " is of 
zero length."
+class RelaxWarning(BaseWarning):
+    def __init__(self, text):
+        self.text = text
 
 
-    # The atom is missing from the PDB file.
-    class RelaxNoAtomWarning(BaseWarning):
-        def __init__(self, atom, res):
-            self.text = "The atom %s could not be found for residue %i" % 
(atom, res)
+# PDB warnings.
+###############
+
+# Zero length XH bond vector.
+class RelaxZeroVectorWarning(BaseWarning):
+    def __init__(self, res):
+        self.text = "The XH bond vector for residue " + `res` + " is of zero 
length."
 
 
-    # The PDB file is missing.
-    class RelaxNoPDBFileWarning(BaseWarning):
-        def __init__(self, file):
-            self.text = "The PDB file %s cannot be found, no structures will 
be loaded." % file
+# The atom is missing from the PDB file.
+class RelaxNoAtomWarning(BaseWarning):
+    def __init__(self, atom, res):
+        self.text = "The atom %s could not be found for residue %i" % (atom, 
res)
+
+
+# The PDB file is missing.
+class RelaxNoPDBFileWarning(BaseWarning):
+    def __init__(self, file):
+        self.text = "The PDB file %s cannot be found, no structures will be 
loaded." % file




Related Messages


Powered by MHonArc, Updated Tue Feb 27 06:20:05 2007