-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlistvariables.py
62 lines (52 loc) · 1.63 KB
/
listvariables.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
"""
V1.2
Modification in recurse:
Recursion to old folders is made independent if found .knime data or not
"""
import sys
import xml.etree.ElementTree as ET
from os import listdir
from os.path import isfile, join
folder = sys.argv[1]
TYPES = {
'STRING' : 'String',
'INTEGER' : 'int',
'DOUBLE' : 'double'
}
def listWorkflows(folder):
list = []
recurse(folder, list)
return list
def recurse(f, list):
content = listdir(f)
isWorkflow = ("workflow.knime" in content) and ("settings.xml" not in content)
if not isWorkflow:
for c in content:
path = join(f,c)
if not isfile(path):
recurse(path, list)
else:
list.append(f)
def createVarFile(workflowknime, outfile):
tree = ET.parse(workflowknime)
root = tree.getroot()
f = open(outfile, "w")
for child in root:
if child.attrib['key'] == 'workflow_variables':
for var in child:
name = None
value = None
typ = None
for entry in var:
if entry.attrib['key'] == 'name':
name = entry.attrib['value']
elif entry.attrib['key'] == 'class':
typ = entry.attrib['value']
elif entry.attrib['key'] == 'value':
value = entry.attrib['value']
f.write(name + ':' + TYPES[typ] + ':' + value + "\n")
break
f.close()
for workflowFolder in listWorkflows(folder):
createVarFile(join(workflowFolder, "workflow.knime"), join(workflowFolder, "dockermeta.knime"))