Hi,

I have fixed the import issue of the RelaxError and RelaxWarning
system within the 'error_import' branch (I talked about the problem in
the post at https://mail.gna.org/public/relax-devel/2007-03/msg00000.html,
Message-id: <[EMAIL PROTECTED]>).
To create all the import statements I have used the attached script
which parses the given module and outputs the required import
statements.  This script could be useful in the future for finding
errors and warnings either missing from the import statement or
imported but not used in the code.

Cheers,

Edward
#! /usr/bin/env python

from re import search
from string import split
import sys


class Create_list:
    def __init__(self):
        """Create lists of the RelaxErrors and RelaxWarnings used in the supplied relax module."""

        # Incorrect usage of the script.
        if len(sys.argv) != 2:
            print "Usage:"
            print "    error_list.py [file]"
            sys.exit()

        # Open the file, read the lines, and then close it.
        file = open(sys.argv[1])
        lines = file.readlines()
        file.close()

        # The lists.
        errors = []
        warnings = []

        # Loop over the lines.
        for line in lines:
            # Remove comments.
            row = split(line, '#')
            text = row[0]

            # Remove import statements.
            if search("import Relax", text):
                continue

            # Find any RelaxErrors.
            match_object = search("Relax.*Error", text)
            if match_object:
                errors.append(match_object.group())

            # Find any RelaxWarnings.
            match_object = search("Relax.*Warning", text)
            if match_object:
                warnings.append(match_object.group())

        # Sort.
        errors.sort()
        warnings.sort()

        # Format the error string.
        error_string = None
        for i in xrange(len(errors)):
            # First error.
            if i == 0:
                error_string = "from relax_errors import " + errors[0]

            # Format the error (skipping duplicates)
            elif errors[i] != errors[i-1]:
                error_string = error_string + ', ' + errors[i]

        # Format the warning string.
        warning_string = None
        for i in xrange(len(warnings)):
            # First warning.
            if i == 0:
                warning_string = "from relax_warnings import " + warnings[0]

            # Format the warning (skipping duplicates)
            elif warnings[i] != warnings[i-1]:
                warning_string = warning_string + ', ' + warnings[i]

        # Print the lists.
        if error_string:
            print error_string
        if warning_string:
            print warning_string


if __name__ == '__main__':
    Create_list()
_______________________________________________
relax (http://nmr-relax.com)

This is the relax-devel mailing list
[email protected]

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-devel

Reply via email to