<commit_before>import xml.dom.minidom
import subprocess
from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, traits,
                                    TraitedSpec, File, StdOutCommandLine,
                                    StdOutCommandLineInputSpec, isdefined)


def generate_all_classes(modules_list = [], launcher=[]):
    """ modules_list contains all the SEM compliant tools that should have wrappers created for them.
        launcher containtains the command line prefix wrapper arugments needed to prepare
        a proper environment for each of the modules.
    """
    init_imports = ""
    for module in modules_list:
        module_python_filename="%s.py"%module
        print("="*80)
        print("Generating Definition for module {0} in {1}".format(module,module_python_filename))
        print("^"*80)
        code = generate_class(module,launcher)
        f = open(module_python_filename, "w")
        f.write(code)
        f.close()
        init_imports += "from %s import %s\n"%(module,module)
    f = open("__init__.py", "w")
    f.write(init_imports)
    f.close()


def generate_class(module,launcher):
    dom = grab_xml(module,launcher)
    inputTraits = []
    outputTraits = []
    outputs_filenames = {}

    #self._outputs_nodes = []

    for paramGroup in dom.getElementsByTagName("parameters"):
        for param in paramGroup.childNodes:
            if param.nodeName in ['label', 'description', '#text', '#comment']:
                continue
            traitsParams = {}

            name = param.getElementsByTagName('name')[0].firstChild.nodeValue

            longFlagNode = param.getElementsByTagName('longflag')
            if longFlagNode:
                traitsParams["argstr"] = "--" + longFlagNode[0].firstChild.nodeValue + " "
            else:
                traitsParams["argstr"] = "--" + name + " "


            argsDict = {'directory': '%s', 'file': '%s', 'integer': "%d", 'double': "%f", 'float': "%f", 'image': "%s", 'transform': "%s", 'boolean': '', 'string-enumeration': '%s', 'string': "%s", 'integer-enumeration' : '%s'}

            if param.nodeName.endswith('-vector'):
                traitsParams["argstr"] += argsDict[param.nodeName[:-7]]
            else:
                traitsParams["argstr"] += argsDict[param.nodeName]

            index = param.getElementsByTagName('index')
            if index:
                traitsParams["position"] = index[0].firstChild.nodeValue

            desc = param.getElementsByTagName('description')
            if index:
                traitsParams["desc"] = desc[0].firstChild.nodeValue

            name = param.getElementsByTagName('name')[0].firstChild.nodeValue

            typesDict = {'integer': "traits.Int", 'double': "traits.Float",
                         'float': "traits.Float", 'image': "File",
                         'transform': "File", 'boolean': "traits.Bool",
                         'string': "traits.Str", 'file':"File",
                         'directory': "Directory"}

            if param.nodeName.endswith('-enumeration'):
                type = "traits.Enum"
                values = ['"%s"'%el.firstChild.nodeValue for el in param.getElementsByTagName('element')]
            elif param.nodeName.endswith('-vector'):
                type = "traits.List"
                if param.nodeName in ['file', 'directory', 'image', 'transform']:
                    values = ["%s(exists=True)"%typesDict[param.nodeName[:-7]]]
                else:
                    values = [typesDict[param.nodeName[:-7]]]
                traitsParams["sep"] = ','
            elif param.getAttribute('multiple') == "true":
                type = "traits.List"
                if param.nodeName in ['file', 'directory', 'image', 'transform']:
                    values = ["%s(exists=True)"%typesDict[param.nodeName[:-7]]]
                else:
                    values = [typesDict[param.nodeName]]
                traitsParams["argstr"] += "..."
            else:
                values = []
                type = typesDict[param.nodeName]

            if param.nodeName in ['file', 'directory', 'image', 'transform'] and param.getElementsByTagName('channel')[0].firstChild.nodeValue == 'output':
                inputTraits.append("%s = traits.Either(traits.Bool, %s, %s)"%(name, type, parse_params(traitsParams)))
                outputTraits.append("%s = %s(exists=True, %s)"%(name, type, parse_params(traitsParams)))

                outputs_filenames[name] = gen_filename_from_param(param)
            else:
                if param.nodeName in ['file', 'directory', 'image', 'transform'] and type not in ["InputMultiPath", "traits.List"]:
                    traitsParams["exists"] = True

                inputTraits.append("%s = %s(%s %s)"%(name, type, parse_values(values), parse_params(traitsParams)))

    input_spec_code = "class " + module + "InputSpec(CommandLineInputSpec):\n"
    for trait in inputTraits:
        input_spec_code += "    " + trait + "\n"
<commit_msg>BUG:  A copy and paste coding error removed<commit_after>import xml.dom.minidom
import subprocess
from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, traits,
                                    TraitedSpec, File, StdOutCommandLine,
                                    StdOutCommandLineInputSpec, isdefined)


def generate_all_classes(modules_list = [], launcher=[]):
    """ modules_list contains all the SEM compliant tools that should have wrappers created for them.
        launcher containtains the command line prefix wrapper arugments needed to prepare
        a proper environment for each of the modules.
    """
    init_imports = ""
    for module in modules_list:
        module_python_filename="%s.py"%module
        print("="*80)
        print("Generating Definition for module {0} in {1}".format(module,module_python_filename))
        print("^"*80)
        code = generate_class(module,launcher)
        f = open(module_python_filename, "w")
        f.write(code)
        f.close()
        init_imports += "from %s import %s\n"%(module,module)
    f = open("__init__.py", "w")
    f.write(init_imports)
    f.close()


def generate_class(module,launcher):
    dom = grab_xml(module,launcher)
    inputTraits = []
    outputTraits = []
    outputs_filenames = {}

    #self._outputs_nodes = []

    for paramGroup in dom.getElementsByTagName("parameters"):
        for param in paramGroup.childNodes:
            if param.nodeName in ['label', 'description', '#text', '#comment']:
                continue
            traitsParams = {}

            name = param.getElementsByTagName('name')[0].firstChild.nodeValue

            longFlagNode = param.getElementsByTagName('longflag')
            if longFlagNode:
                traitsParams["argstr"] = "--" + longFlagNode[0].firstChild.nodeValue + " "
            else:
                traitsParams["argstr"] = "--" + name + " "


            argsDict = {'directory': '%s', 'file': '%s', 'integer': "%d", 'double': "%f", 'float': "%f", 'image': "%s", 'transform': "%s", 'boolean': '', 'string-enumeration': '%s', 'string': "%s", 'integer-enumeration' : '%s'}

            if param.nodeName.endswith('-vector'):
                traitsParams["argstr"] += argsDict[param.nodeName.replace('-vector','')]
            else:
                traitsParams["argstr"] += argsDict[param.nodeName]

            index = param.getElementsByTagName('index')
            if index:
                traitsParams["position"] = index[0].firstChild.nodeValue

            desc = param.getElementsByTagName('description')
            if index:
                traitsParams["desc"] = desc[0].firstChild.nodeValue

            name = param.getElementsByTagName('name')[0].firstChild.nodeValue

            typesDict = {'integer': "traits.Int", 'double': "traits.Float",
                         'float': "traits.Float", 'image': "File",
                         'transform': "File", 'boolean': "traits.Bool",
                         'string': "traits.Str", 'file':"File",
                         'directory': "Directory"}

            if param.nodeName.endswith('-enumeration'):
                type = "traits.Enum"
                values = ['"%s"'%el.firstChild.nodeValue for el in param.getElementsByTagName('element')]
            elif param.nodeName.endswith('-vector'):
                type = "traits.List"
                if param.nodeName in ['file', 'directory', 'image', 'transform']:
                    values = ["%s(exists=True)"%typesDict[param.nodeName.replace('-vector','')]]
                else:
                    values = [typesDict[param.nodeName.replace('-vector','')]]
                traitsParams["sep"] = ','
            elif param.getAttribute('multiple') == "true":
                type = "traits.List"
                if param.nodeName in ['file', 'directory', 'image', 'transform']:
                    values = ["%s(exists=True)"%typesDict[param.nodeName]]
                else:
                    values = [typesDict[param.nodeName]]
                traitsParams["argstr"] += "..."
            else:
                values = []
                type = typesDict[param.nodeName]

            if param.nodeName in ['file', 'directory', 'image', 'transform'] and param.getElementsByTagName('channel')[0].firstChild.nodeValue == 'output':
                inputTraits.append("%s = traits.Either(traits.Bool, %s, %s)"%(name, type, parse_params(traitsParams)))
                outputTraits.append("%s = %s(exists=True, %s)"%(name, type, parse_params(traitsParams)))

                outputs_filenames[name] = gen_filename_from_param(param)
            else:
                if param.nodeName in ['file', 'directory', 'image', 'transform'] and type not in ["InputMultiPath", "traits.List"]:
                    traitsParams["exists"] = True

                inputTraits.append("%s = %s(%s %s)"%(name, type, parse_values(values), parse_params(traitsParams)))

    input_spec_code = "class " + module + "InputSpec(CommandLineInputSpec):\n"
    for trait in inputTraits:
        input_spec_code += "    " + trait + "\n"

{'fraction_non_alphanumeric': 0.1457921770051363, 'fraction_numerical': 0.002765705254839984, 'mean_word_length': 2.2629713180792783, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1680873', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2743, 'n_words': 577}