mailScript for creating a list of all the RelaxErrors and RelaxWarnings in a module.


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

Header


Content

Posted by Edward d'Auvergne on March 02, 2007 - 07:23:
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: <7f080ed10703012125m7e6dff3du21e49d888cad2c02@xxxxxxxxxxxxxx>).
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()

Related Messages


Powered by MHonArc, Updated Sun Mar 04 09:40:18 2007