comparison findToolsWithoutTests.py @ 6:7a6f2380fc1d draft

planemo upload for repository https://forgemia.inra.fr/metexplore/met4j-galaxy
author metexplore
date Wed, 17 May 2023 13:26:37 +0000
parents
children
comparison
equal deleted inserted replaced
5:35c9abcd8934 6:7a6f2380fc1d
1 import os
2 import xml.etree.ElementTree as ET
3
4 def find_xml_files_without_tests(directory):
5 for filename in os.listdir(directory):
6 filepath = os.path.join(directory, filename)
7 if os.path.isdir(filepath):
8 # Récursivement, recherche dans les sous-répertoires
9 yield from find_xml_files_without_tests(filepath)
10 elif filename.endswith(".xml"):
11 # Traitement du fichier XML
12 tree = ET.parse(filepath)
13 root = tree.getroot()
14 tool_elements = root.findall(".//tool")
15 tests_elements = root.findall(".//tests")
16 if tool_elements and not tests_elements:
17 yield filepath
18 elif tests_elements:
19 # On vérifie qu'il n'y a rien à l'intérieur de <tests>
20 tests_children = list(tests_elements[0])
21 if len(tests_children) == 0:
22 yield filepath
23
24 if __name__ == "__main__":
25 import argparse
26 parser = argparse.ArgumentParser(description="Trouve les fichiers XML sans élément <tests>")
27 parser.add_argument("directory", metavar="DIRECTORY", type=str, help="Le répertoire à explorer")
28 args = parser.parse_args()
29
30 for filepath in find_xml_files_without_tests(args.directory):
31 print(filepath)