-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_requirements.py
35 lines (26 loc) · 1.12 KB
/
extract_requirements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
import os.path
import sys
from xml.dom.minidom import parse
PATH = "tools"
def extract_requirements(args, dirname, names):
no_requirements = []
for name in names:
path = os.path.join(dirname, name)
if path.endswith(".xml"):
dom = parse(path)
tools = dom.getElementsByTagName("tool")
for tool in tools:
requirements = tool.getElementsByTagName("requirement")
tool_name = tool.getAttribute("name")
if len(requirements) > 0:
requirements = ", ".join(requirement.childNodes[0].data+("("+requirement.getAttribute("version")+")" if requirement.getAttribute("version") != "" else "") for requirement in requirements)
print "%s : %s" % (tool_name, requirements)
def main():
if len(sys.argv) != 2:
print >> sys.stderr, 'usage: extract-requirements <galaxy_tools_path>'
sys.exit(1)
if not os.path.exists(sys.argv[1]):
print >> sys.stderr, 'unknown path', sys.argv[1]
sys.exit(1)
os.path.walk(sys.argv[1], extract_requirements, None)