1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import configuration
21 import amara
22
25 self.testxml = testxml
26 self.doc = amara.parse(testxml)
27
29 for p in self.doc.xml_xpath("//property"):
30 if str(p.name) == name:
31 return str(p.value) == value
32 return False
33
35 for p in self.doc.xml_xpath("//setting"):
36 if str(p.name) == name:
37 return str(p.value) == value
38 return False
39
41 changed = False
42 for p in self.doc.xml_xpath("//setting"):
43 if str(p.name) == name:
44 p.value = value
45 changed = True
46 if not changed:
47 for device in self.doc.test.target.device:
48 device.xml_append(self.doc.xml_create_element(u"setting", attributes = {u'name': unicode(name), u'value': unicode(value)}))
49
51 for p in self.doc.xml_xpath("//*[@" + name + "]"):
52 if p[name] == value:
53 return True
54 return False
55
57 for p in self.doc.xml_xpath("//*[@" + name + "]"):
58 p[name] = value
59
61 changed = False
62 for p in self.doc.xml_xpath("//property"):
63 if str(p.name) == name:
64 p.value = value
65 changed = True
66 if not changed:
67 for device in self.doc.test.target.device:
68 device.xml_append(self.doc.xml_create_element(u"property", attributes = {u'name': unicode(name), u'value': unicode(value)}))
69
70
76
78 props = {}
79 for config in self.configs:
80 if (config.type == "properties"):
81 for subconfig in config:
82 props[subconfig] = config[subconfig]
83 return props
84
86 settings = {}
87 for config in self.configs:
88 if (config.type == "settings"):
89 for subconfig in config:
90 settings[subconfig] = config[subconfig]
91 return settings
92
94 specfile = open(specfilename)
95
96 builder = configuration.NestedConfigurationBuilder(specfile)
97 configs = builder.getConfigurations("common")
98
99 testxml = TestXML(testxmldata)
100
101 for config in configs:
102 if (config.type == "properties"):
103 for subconfig in config:
104 testxml.addorreplaceproperty(subconfig, config[subconfig])
105 if (config.type == "conditional_properties"):
106 check = config.name.split(',')
107 if testxml.containsproperty(check[0], check[1]):
108 for subconfig in config:
109 testxml.addorreplaceproperty(subconfig, config[subconfig])
110 if (config.type == "settings"):
111 for subconfig in config:
112 testxml.addorreplacesetting(subconfig, config[subconfig])
113 if (config.type == "conditional_settings"):
114 check = config.name.split(',')
115 if testxml.containssetting(check[0], check[1]):
116 for subconfig in config:
117 testxml.addorreplacesetting(subconfig, config[subconfig])
118 if (config.type == "attributes"):
119 for subconfig in config:
120 testxml.replaceattribute(subconfig, config[subconfig])
121 if (config.type == "conditional_attributes"):
122 check = config.name.split(',')
123 if testxml.containsattribute(check[0], check[1]):
124 for subconfig in config:
125 testxml.replaceattribute(subconfig, config[subconfig])
126
127 return testxml.doc.xml(indent=u"yes")
128