forked from beaker-project/beaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsanitize_xml.py
More file actions
executable file
·50 lines (46 loc) · 1.97 KB
/
Copy pathsanitize_xml.py
File metadata and controls
executable file
·50 lines (46 loc) · 1.97 KB
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
#!/usr/bin/python
#Simple helper to remove confidential data from xml results
import sys
import xml.dom.minidom
tasks = {}
count = 0
doc = xml.dom.minidom.Document()
oldjob = xml.dom.minidom.parseString(open(sys.argv[1]).read()).getElementsByTagName('job')[0]
newjob = doc.createElement('job')
def handle_recipe(element, node):
global count
new_r = doc.createElement(element)
new_r.setAttribute('result', node.getAttribute('result'))
new_r.setAttribute('status', node.getAttribute('status'))
new_r.setAttribute('whiteboard', '')
new_dr = doc.createElement('distroRequires')
new_dn = doc.createElement('distro_name')
new_dn.setAttribute('op','=')
new_dn.setAttribute('value','BlueShoeLinux5-5')
new_dr.appendChild(new_dn)
new_r.appendChild(new_dr)
new_r.appendChild(doc.createElement('hostRequires'))
for child in node.childNodes:
if child.nodeName == 'guestrecipe':
new_r.appendChild(handle_recipe('guestrecipe', child))
if child.nodeName == 'task':
new_t = doc.createElement('task')
if child.getAttribute('name') not in tasks:
tasks[child.getAttribute('name')] = '/fake/Task/task%s' % count
count += 1
new_t.setAttribute('name', tasks[child.getAttribute('name')])
new_t.setAttribute('result', child.getAttribute('result'))
new_t.setAttribute('status', child.getAttribute('status'))
new_r.appendChild(new_t)
return new_r
newjob.setAttribute('result', oldjob.getAttribute('result'))
newjob.setAttribute('status', oldjob.getAttribute('status'))
newjob.appendChild(doc.createElement('whiteboard'))
for old_rs in oldjob.getElementsByTagName('recipeSet'):
new_rs = doc.createElement('recipeSet')
for child in old_rs.childNodes:
if child.nodeName == 'recipe':
new_r = handle_recipe('recipe', child)
new_rs.appendChild(new_r)
newjob.appendChild(new_rs)
print newjob.toprettyxml()