Mercurial > repos > metexplore > met4j
view findToolsWithoutTests.py @ 8:1274e2a62479 draft default tip
planemo upload for repository https://forgemia.inra.fr/metexplore/met4j-galaxy commit e34acf0f51cafcf6ae7c97b4feb3188a39f17c32
author | metexplore |
---|---|
date | Wed, 26 Jul 2023 15:33:45 +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)