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
63
64
65
|
# File 'lib/constraintClean.rb', line 4
def cleanupConstraints(file)
f = File.open(file)
doc = Nokogiri::XML(f)
f.close
excluded = []
variations = doc.xpath('//variation')
included = doc.xpath('//include')
outlets = doc.xpath('//outlet')
variations.each do |variation|
if variation.attr('key') == "default"
ch = variation.children
ch.each do |mask|
constraints = mask.children
constraints.each do |constraint|
if constraint.name == 'exclude'
excluded.push(constraint)
end
end
end
end
end
result = []
excluded.each do |node|
found = false
for includedNode in included
p node
if node.attr('reference') == includedNode.attr('reference')
found = true
break
end
end
if !found
for outlet in outlets
if node.attr('reference') == outlet.attr('destination')
found = true
break
end
end
end
if !found
result.push(node)
nodeID = node.attr('reference')
constraints = doc.xpath("//constraint[@id='#{nodeID}']")
result += constraints
end
end
if result.count > 0
f1 = File.open(file, 'w')
result.each{ |node| node.remove }
f1.write(doc.to_xml)
f1.close
p "removed #{result.count} constraint(s) from #{file}"
end
end
|