mailr2532 - in /branches/nan_catch_test: errors.py generic_fns/pdb.py prompt/interpreter.py relax


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

Header


Content

Posted by edward on August 10, 2006 - 12:15:
Author: bugman
Date: Thu Aug 10 12:15:24 2006
New Revision: 2532

URL: http://svn.gna.org/viewcvs/relax?rev=2532&view=rev
Log:
Created the RelaxWarning subsystem.  The standard 'RelaxWarning' and the 
'RelaxZeroVectorWarning'
warning classes have been created.


Modified:
    branches/nan_catch_test/errors.py
    branches/nan_catch_test/generic_fns/pdb.py
    branches/nan_catch_test/prompt/interpreter.py
    branches/nan_catch_test/relax

Modified: branches/nan_catch_test/errors.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/nan_catch_test/errors.py?rev=2532&r1=2531&r2=2532&view=diff
==============================================================================
--- branches/nan_catch_test/errors.py (original)
+++ branches/nan_catch_test/errors.py Thu Aug 10 12:15:24 2006
@@ -23,7 +23,11 @@
 import __builtin__
 from re import match
 from types import ClassType
-
+import warnings
+
+
+# Error objects.
+################
 
 class RelaxErrors:
     def __init__(self):
@@ -476,3 +480,68 @@
     class RelaxNaNError(BaseError):
         def __init__(self, name):
             self.text = "The invalid " + name + " floating point value of 
NaN (Not a Number) has occurred."
+
+
+
+# Warning objects.
+##################
+
+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,
+
+        # Change the formatting of the warning message.
+        warnings.formatwarning = self.format
+
+
+    def format(self, message, category, filename, lineno):
+        """Change the warning message formatting."""
+
+        # The RelaxWarning string.
+        string = "RelaxWarning: %s\n" % message
+
+        return string
+
+
+    # Base class for all warnings.
+    ############################
+
+    class BaseWarning(Warning):
+        def __str__(self):
+            return (self.text + "\n")
+
+
+    # Standard warnings.
+    ####################
+
+    class RelaxWarning(BaseWarning):
+        def __init__(self, text):
+            self.text = text
+
+
+    # Zero length vector.
+    #####################
+
+    class RelaxZeroVectorWarning(BaseWarning):
+        def __init__(self, res):
+            self.text = "The XH bond vector for residue " + `res` + " is of 
zero length."
+
+

Modified: branches/nan_catch_test/generic_fns/pdb.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/nan_catch_test/generic_fns/pdb.py?rev=2532&r1=2531&r2=2532&view=diff
==============================================================================
--- branches/nan_catch_test/generic_fns/pdb.py (original)
+++ branches/nan_catch_test/generic_fns/pdb.py Thu Aug 10 12:15:24 2006
@@ -268,8 +268,10 @@
 
                     # Test for zero length.
                     if norm_factor == 0.0:
-                        if self.print_flag:
-                            print "The XH bond vector for residue " + 
`self.relax.data.res[self.run][j].num` + " is of zero length."
+                        # Warning.
+                        
warn(RelaxZeroVector(self.relax.data.res[self.run][j].num))
+
+                        # Set the vector to None.
                         self.relax.data.res[self.run][j].xh_vect.append(None)
 
                     # Calculate the normalised vector.

Modified: branches/nan_catch_test/prompt/interpreter.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/nan_catch_test/prompt/interpreter.py?rev=2532&r1=2531&r2=2532&view=diff
==============================================================================
--- branches/nan_catch_test/prompt/interpreter.py (original)
+++ branches/nan_catch_test/prompt/interpreter.py Thu Aug 10 12:15:24 2006
@@ -301,7 +301,10 @@
             else:
                 more = self.push(line)
         except KeyboardInterrupt:
-            self.write("\nKeyboardInterrupt\n")
+            if Debug:
+                self.showtraceback()
+            else:
+                self.write("\nKeyboardInterrupt\n")
             self.resetbuffer()
             more = 0
 
@@ -345,6 +348,11 @@
             self.showtraceback()
         else:
             sys.stderr.write(instance.__str__())
+    except AllRelaxWarnings, instance:
+        if Debug:
+            self.showtraceback()
+        else:
+            sys.stderr.write(instance.__str__())
     except:
         raise
 

Modified: branches/nan_catch_test/relax
URL: 
http://svn.gna.org/viewcvs/relax/branches/nan_catch_test/relax?rev=2532&r1=2531&r2=2532&view=diff
==============================================================================
--- branches/nan_catch_test/relax (original)
+++ branches/nan_catch_test/relax Thu Aug 10 12:15:24 2006
@@ -41,6 +41,7 @@
 from re import match
 from string import split, strip
 import sys
+from warnings import warn
 
 # Numeric.
 try:
@@ -66,7 +67,7 @@
 # relax modules.
 from colour import Colour
 from data import Data
-from errors import RelaxErrors
+from errors import RelaxErrors, RelaxWarnings
 from io import IO
 from generic_fns.main import Generic
 from prompt.gpl import gpl
@@ -92,8 +93,10 @@
         # Get and store the PID of this process.
         self.pid = getpid()
 
-        # Set up the program internal errors.
+        # Set up the program internal errors and warnings.
         RelaxErrors()
+        RelaxWarnings()
+        __builtin__.warn = warn
 
         # Debugging flag (default is off).
         __builtin__.Debug = 0




Related Messages


Powered by MHonArc, Updated Thu Aug 10 12:40:06 2006