~oem-qa/checkbox/patch_deselect_ancestors_when_no_child_is_selected

« back to all changes in this revision

Viewing changes to scripts/mago_filter

Imported scripts and jobs from Platform Services.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import sys
 
4
 
 
5
from xml.dom import minidom
 
6
 
 
7
from optparse import OptionParser
 
8
 
 
9
 
 
10
def print_line(key, value):
 
11
    print "%s: %s" % (key, value)
 
12
 
 
13
def print_element(element):
 
14
    for key, value in element.items():
 
15
        print_line(key, value)
 
16
 
 
17
    print
 
18
 
 
19
def parse_file(file):
 
20
    elements = []
 
21
    default_status = "pass"
 
22
    tree = minidom.parse(file)
 
23
    for suite in tree.getElementsByTagName("suite"):
 
24
        element = {}
 
25
        element["plugin"] = "local"
 
26
        element["status"] = default_status
 
27
        element["name"] = suite.getAttribute("name")
 
28
        for child in suite.childNodes:
 
29
            if child.nodeName == "description":
 
30
                element["description"] = child.firstChild.data.strip()
 
31
            elif child.nodeName == "result":
 
32
                for subchild in child.childNodes:
 
33
                    if subchild.nodeName == "pass":
 
34
                        data = subchild.firstChild.data
 
35
                        element["status"] = data == "1" and "pass" or "fail"
 
36
                    elif subchild.nodeName == "error":
 
37
                        element["status"] = "fail"
 
38
 
 
39
                if element["status"] == "fail":
 
40
                    default_status = "unresolved"
 
41
 
 
42
        elements.append(element)
 
43
 
 
44
        for case in suite.getElementsByTagName("case"):
 
45
            element = {}
 
46
            element["plugin"] = "shell"
 
47
            element["status"] = default_status
 
48
            element["suite"] = suite.getAttribute("name")
 
49
            element["name"] = case.getAttribute("name")
 
50
            for child in case.childNodes:
 
51
                if child.nodeName == "description":
 
52
                    element["description"] = child.firstChild.data.strip()
 
53
                elif child.nodeName == "result":
 
54
                    for subchild in child.childNodes:
 
55
                        if subchild.nodeName == "time":
 
56
                            data = subchild.firstChild.data
 
57
                            element["duration"] = float(data)
 
58
                        elif subchild.nodeName == "message":
 
59
                            element["data"] = subchild.firstChild.data
 
60
                        elif subchild.nodeName == "pass":
 
61
                            data = subchild.firstChild.data
 
62
                            element["status"] = data == "1" and "pass" or "fail"
 
63
                        elif subchild.nodeName == "error":
 
64
                            element["status"] = "fail"
 
65
 
 
66
            elements.append(element)
 
67
 
 
68
    return elements
 
69
 
 
70
def parse_files(files):
 
71
    elements = []
 
72
    for file in files:
 
73
        elements.extend(parse_file(file))
 
74
 
 
75
    return elements
 
76
 
 
77
def main(args):
 
78
    usage = "Usage: %prog [FILE...]"
 
79
    parser = OptionParser(usage=usage)
 
80
    (options, args) = parser.parse_args(args)
 
81
 
 
82
    if not args:
 
83
        files = [sys.stdin]
 
84
    else:
 
85
        files = args
 
86
 
 
87
    elements = parse_files(files)
 
88
    if not elements:
 
89
        return 1
 
90
 
 
91
    for element in elements:
 
92
        print_element(element)
 
93
 
 
94
    return 0
 
95
 
 
96
 
 
97
if __name__ == "__main__":
 
98
    sys.exit(main(sys.argv[1:]))