view findToolsWithoutTests.py @ 7:1436e9cde9c9 draft

planemo upload for repository https://forgemia.inra.fr/metexplore/met4j-galaxy commit 1d31a48bf8328b7a3ad9910971d24b9f453459c5
author metexplore
date Tue, 04 Jul 2023 10:21:26 +0000
parents 7a6f2380fc1d
children
line wrap: on
line source

import os
import xml.etree.ElementTree as ET

def find_xml_files_without_tests(directory):
    for filename in os.listdir(directory):
        filepath = os.path.join(directory, filename)
        if os.path.isdir(filepath):
            # Récursivement, recherche dans les sous-répertoires
            yield from find_xml_files_without_tests(filepath)
        elif filename.endswith(".xml"):
            # Traitement du fichier XML
            tree = ET.parse(filepath)
            root = tree.getroot()
            tool_elements = root.findall(".//tool")
            tests_elements = root.findall(".//tests")
            if tool_elements and not tests_elements:
                yield filepath
            elif tests_elements:
                # On vérifie qu'il n'y a rien à l'intérieur de <tests>
                tests_children = list(tests_elements[0])
                if len(tests_children) == 0:
                    yield filepath

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description="Trouve les fichiers XML sans élément <tests>")
    parser.add_argument("directory", metavar="DIRECTORY", type=str, help="Le répertoire à explorer")
    args = parser.parse_args()

    for filepath in find_xml_files_without_tests(args.directory):
        print(filepath)