mailr2538 - in /1.2: errors.py relax


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

Header


Content

Posted by c . a . macraild on August 17, 2006 - 17:46:
Author: macraild
Date: Thu Aug 17 17:45:43 2006
New Revision: 2538

URL: http://svn.gna.org/viewcvs/relax?rev=2538&view=rev
Log:
Rolling back revisions 2535-2537

See discussions in the thread starting:
https://mail.gna.org/public/relax-devel/2006-08/msg00052.html


Modified:
    1.2/errors.py
    1.2/relax

Modified: 1.2/errors.py
URL: 
http://svn.gna.org/viewcvs/relax/1.2/errors.py?rev=2538&r1=2537&r2=2538&view=diff
==============================================================================
--- 1.2/errors.py (original)
+++ 1.2/errors.py Thu Aug 17 17:45:43 2006
@@ -21,228 +21,9 @@
 
###############################################################################
 
 import __builtin__
-from re import match, search
-from traceback import extract_stack, format_list
+from re import match
 from types import ClassType
 import time
-import sys
-
-
-class RelaxErrorSystem:
-    def __init__(self, relax, UI_mode=None):
-        """The relax error and warning system."""
-
-        # Arguments.
-        self.relax = relax
-        self.UI_mode = UI_mode
-
-        # Instant exiting modes (i.e. no error system is necessary).
-        if UI_mode == 'version':
-            return
-
-        # Loop over the errors, set their error handling functions, and pack 
them into __builtin__.
-        self.initialise_errors()
-
-
-    def error(self, message, traceback=0, save=0):
-        """Default error function - traceback (Debug), error message, then 
sys.exit()."""
-
-        # Save the program state.
-        if save:
-            self.save_state()
-
-        # Write the traceback to stderr.
-        if traceback and not self.UI_mode == 'prompt':
-            self.traceback()
-
-        # Write the error message to stderr.
-        sys.stderr.write("RelaxError: " + message + "\n")
-
-        # Hard exit (and return 1 to indicate failure)!
-        sys.exit(1)
-
-
-    def error_no_exit(self, message, traceback=0, save=0):
-        """Error function without exit - print traceback (Debug) and error 
message but don't exit."""
-
-        # Save the program state.
-        if save:
-            self.save_state()
-
-        # Write the traceback to stderr.
-        if traceback and not self.UI_mode == 'prompt':
-            self.traceback()
-
-        # Write the error message to stderr.
-        sys.stderr.write("RelaxError: " + message + "\n\n\n")
-
-
-    def initialise_errors(self):
-        """Set the error handling functions and place the errors into 
__builtin__."""
-
-        # Loop over all objects in 'self'.
-        for name in dir(self):
-            # Get the object.
-            object = getattr(self, name)
-
-            # Skip over all non error/warning class objects.
-            if type(object) != ClassType or not search('^Relax', name):
-                continue
-
-            # Instantiate the object.
-            instance = object()
-
-
-            # Place data structures and functions into the RelaxError and 
RelaxWarning instances.
-            
#####################################################################################
-
-            # Place the relax data structure into the instance.
-            instance.relax = self.relax
-
-            # Place the save state function into the instance.
-            #instance.save_state = self.save_state
-
-            # Set up the RelaxError handling functions.
-            if search('Error$', name):
-                # Default error.
-                instance.exception = self.error
-
-                # Don't exit the program in prompt mode when an error occurs.
-                if self.UI_mode == 'prompt':
-                    instance.exception = self.error_no_exit
-
-            # Set up the RelaxWarning handling functions.
-            if search('Warning$', name):
-                # Default warning.
-                instance.exception = self.warning
-
-            # Place the errors into __builtin__
-            __builtin__.__setattr__(name, instance)
-
-            # Tuple of all the errors.
-            if hasattr(__builtin__, 'AllRelaxErrors'):
-                __builtin__.AllRelaxErrors = __builtin__.AllRelaxErrors, 
instance
-            else:
-                __builtin__.AllRelaxErrors = instance,
-
-
-    def save_state(self):
-        """Function for saving the program state (self.relax.data) into a 
temporary file."""
-
-        # Get the current time.
-        now = time.localtime()
-
-        # Format the file name.
-        file_name = "relax_state_%i%02i%02i_%02i%02i%02i" % (now[0], now[2], 
now[1], now[3], now[4], now[5])
-
-        # Save the program state.
-        self.relax.interpreter._State.save(file_name)
-
-
-    def traceback(self):
-        """Function for formatting and printing out the traceback."""
-
-        # Get the stack.
-        stack = extract_stack()
-
-        # Initialise the trimmed stack and stack start flag.
-        trimmed_stack = []
-        start = 0
-
-        # Trim the stack (script mode):
-        if self.UI_mode == 'script':
-            for i in xrange(len(stack)):
-                # Find the 'interact_script()' function, the start of the 
scripting.
-                if stack[i][2] == 'interact_script':
-                    start = 1
-                    continue
-
-                # Not at the start of the script section of the stack.
-                if not start:
-                    continue
-
-                # Append the next item.
-                trimmed_stack.append(stack[i])
-
-                # Find the RelaxError and then stop.
-                if search('^Relax.*Error', stack[i][3]):
-                    break
-
-        # Trim the stack (default).
-        else:
-            for i in xrange(len(stack)):
-                # Append the next item.
-                trimmed_stack.append(stack[i])
-
-                # Find the RelaxError and then stop.
-                if search('^Relax.*Error', stack[i][3]):
-                    break
-
-        # Default formatting of the stack.
-        string_stack = format_list(trimmed_stack)
-
-        # Print out the formatted stack.
-        for i in xrange(len(string_stack)):
-            sys.stderr.write(string_stack[i])
-
-
-    def warning(self, message):
-        """Default warning function - just print the warning message."""
-
-        # Write the warning message to stderr.
-        sys.stderr.write("RelaxWarning: " + message + "\n")
-
-
-    def warning_pedantic(self, message, save=0):
-        """Pedantic warning function - print the warning message then 
exit."""
-
-        # Save the program state.
-        if save:
-            self.save_state()
-
-        # Write the warning message to stderr.
-        sys.stderr.write("RelaxWarning: " + message + "\n")
-
-        # Hard exit (and return 1 to indicate failure)!
-        sys.exit(1)
-
-
-
-    ####################
-    # The RelaxErrors. #
-    ####################
-
-    class RelaxBadError:
-        def __init__(self):
-            """This error is really BAD!!!"""
-
-        def __call__(self, text):
-
-            # Format the message.
-            message = text + " - This error is very, very bad."
-
-            # Run the error handling code.
-            self.exception(message, traceback=Debug, save=Debug)
-
-
-
-    ######################
-    # The RelaxWarnings. #
-    ######################
-
-    class RelaxBadWarning:
-        def __init__(self):
-            """This warning is really BAD!!!"""
-
-        def generate(self, text):
-            # Format the message.
-            message = text + " - This warning is very, very bad."
-
-            # Run the error handling code.
-            self.exception(message)
-
-
-
 
 
 class RelaxErrors:
@@ -277,7 +58,6 @@
     class BaseError(Exception):
         def __str__(self):
             return ("RelaxError: " + self.text + "\n")
-
         def save_state(self):
             now = time.localtime()
             file_name = "relax_state_%i%02i%02i_%02i%02i%02i" % (now[0], 

Modified: 1.2/relax
URL: 
http://svn.gna.org/viewcvs/relax/1.2/relax?rev=2538&r1=2537&r2=2538&view=diff
==============================================================================
--- 1.2/relax (original)
+++ 1.2/relax Thu Aug 17 17:45:43 2006
@@ -66,7 +66,7 @@
 # relax modules.
 from colour import Colour
 from data import Data
-from errors import RelaxErrorSystem, RelaxErrors
+from errors import RelaxErrors
 from io import IO
 from generic_fns.main import Generic
 from prompt.gpl import gpl
@@ -128,9 +128,6 @@
         # Process the command line arguments and determine the relax mode.
         mode, log_file, tee_file = self.arguments()
 
-        # Set up the relax error system.
-        RelaxErrorSystem(self, UI_mode=mode)
-
         # Show the version number and exit.
         if mode == 'version':
             print 'relax ' + self.version




Related Messages


Powered by MHonArc, Updated Thu Aug 17 18:00:05 2006