summaryrefslogtreecommitdiff
path: root/gpscap.py
blob: cd6603b7813544b1b4376fd6d1c1984abc6b206b (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""

gpscap - GPS capability dictionary class.

"""
import ConfigParser

class GPSDictionary(ConfigParser.RawConfigParser):
    def __init__(self, *files):
        "Initialize the capability dictionary"
        ConfigParser.RawConfigParser.__init__(self)
        if not files:
            files = ["gpscap.ini", "/usr/share/gpsd/gpscap.ini"]
        self.read(files)
        # Resolve uses= members
        while True:
            keepgoing = False
            for section in self.sections():
                if self.has_option(section, "uses"):
                    parent = self.get(section, "uses")
                    if self.has_option(parent, "uses"):
                        continue
                    # Found a parent section without a uses = part.
                    for heritable in self.options(parent):
                        if not self.has_option(section, heritable):
                            self.set(section,
                                     heritable,
                                     self.get(parent, heritable))
                            keepgoing = True
                    self.remove_option(section, "uses")
            if not keepgoing:
                break
        # Sanity check: All items must have a type field.
        for section in self.sections():
            if not self.has_option(section, "type"):
                raise ConfigParser.Error("%s has no type" % section)
            elif self.get(section, "type") not in ("engine", "vendor", "device"):
                raise ConfigParser.Error("%s has invalid type" % section)
        # Sanity check: All devices must point at a vendor object.
        # Side effect: build the lists of vendors and devices.
        self.vendors = []
        self.devices = []
        for section in self.sections():
            if self.get(section, "type") == "vendor":
                self.vendors.append(section)
            if self.get(section, "type") == "device":
                self.devices.append(section)
        self.vendors.sort()
        for section in self.sections():
            if self.get(section, "type") == "device":
                if not self.has_option(section, "vendor"):
                    raise ConfigParser.Error("%s has no vendor" % section)
                if self.get(section, "vendor") not in self.vendors:
                    raise ConfigParser.Error("%s has invalid vendor" % section)

    def HTMLDump(self, ofp):
        thead = """<table border='1' style='font-size:small;' bgcolor='#CCCCCC'>
<tr>
<th>Name</th>
<th>Packaging</th>
<th>Engine</th>
<th>Interface</th>
<th>Tested with</th>
<th>NMEA version</th>
<th width='50%'>Notes</th>
</tr>
"""
        vhead = "<tr><td style='text-align:center;' colspan='7'><a href='%s'>%s</a></td></tr>\n"
        ofp.write(thead)
        for vendor in self.vendors:
            ofp.write(vhead % (self.get(vendor, "vendor_site"), vendor))
            relevant = []
            for dev in self.devices:
                if self.get(dev, "vendor") == vendor:
                    relevant.append(dev)
            relevant.sort()
            for dev in relevant:
                rowcolor = "#FFFFFF"
                if self.has_option(dev, "broken"):
                    rowcolor = "Pink"
                elif self.get(dev, "packaging") == "OEM module":
                    rowcolor = "LimeGreen"
                elif self.get(dev, "packaging") == "chipset":
                    rowcolor = "LightYellow"
                elif self.get(dev, "packaging") == "handset":
                    rowcolor = "Cyan"
                elif self.get(dev, "packaging") == "car mount":
                    rowcolor = "DarkCyan"

                ofp.write("<tr bgcolor='%s'>\n" % rowcolor)
                ofp.write("<td>%s</td>\n" % dev)
                ofp.write("<td>%s</td>\n" % self.get(dev, "packaging"))
                ofp.write("<td>%s</td>\n" % self.get(dev, "engine"))
                ofp.write("<td>%s</td>\n" % self.get(dev, "interfaces"))
                tested = ""
                if self.has_option(dev, "broken"):
                    tested = "Broken"
                elif self.get(dev, "tested") == "regression":
                    tested = "*"
                else:
                    tested = self.get(dev, "tested")
                ofp.write("<td>%s</td>\n" % tested)
                nmea = "&nbsp;"
                if self.has_option(dev, "nmea"):
                    nmea = self.get(dev, "nmea")
                ofp.write("<td>%s</td>\n" % nmea)
                ofp.write("<td>%s</td>\n" % self.get(dev, "notes"))
                ofp.write("</tr>\n")
        ofp.write("</table>\n")


if __name__ == "__main__":
    import sys
    d = GPSDictionary()
    d.HTMLDump(sys.stdout)