Zoltan2
 All Namespaces Files Functions Variables Pages
checkXMLParameters.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 #
3 # Element is available in python 1.5.2 and higher.
4 # It can be downloaded to use with older python.
5 #
6 # This script does some basic validity checks on parameters.xml.
7 
8 import elementtree.ElementTree as ET
9 import sys
10 
11 ##
12 ## Begin
13 ##
14 
15 tree = ET.parse("./parameters.xml")
16 
17 root = tree.getroot()
18 
19 if root.tag != "ParameterList":
20  print "Error: Root tag is not ParameterList"
21  sys.exit(1)
22 
23 validators = []
24 for node in root:
25  if node.tag == "Validators":
26  validators = node
27  break
28 
29 if len(validators) == 0:
30  print "Error: This is not a valid Zoltan2 parameter list."
31  sys.exit(1)
32 
33 
34 # Create a dictionary of Validators
35 
36 vals={}
37 
38 for node in validators:
39  id = node.get("validatorId")
40  if id in vals:
41  print "Error: Validator ID ",id," is repeated."
42  sys.exit(1)
43 
44  vals[id] = node
45 
46 ##
47 # Match up parameters to validators
48 ##
49 
50 idList = []
51 fail = False
52 
53 for node in root:
54  if node.tag != "Parameter":
55  continue
56  paramName = node.get("name")
57  paramId = node.get("id")
58  validatorId = node.get("validatorId")
59 
60  if paramId in idList:
61  print "Error: Parameter id ",paramId," is reused for ",paramName
62  fail = True
63  break
64 
65  idList.append(paramId)
66 
67  if validatorId not in vals.keys():
68  print "Error: Parameter ",paramName," has invalid validator ID ",validatorId
69  fail = True
70  break
71 
72 if fail == True:
73  print "Looks OK"
74 
75