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