3 gpscap - GPS/AIS capability dictionary class.
5 This file is Copyright (c) 2010 by the GPSD project
6 BSD terms apply: see the file COPYING in the distribution root for details.
10 class GPSDictionary(ConfigParser.RawConfigParser):
11 def __init__(self, *files):
12 "Initialize the capability dictionary"
13 ConfigParser.RawConfigParser.__init__(self)
15 files = ["gpscap.ini", "/usr/share/gpsd/gpscap.ini"]
17 # Resolve uses= members
20 for section in self.sections():
21 if self.has_option(section, "uses"):
22 parent = self.get(section, "uses")
23 if self.has_option(parent, "uses"):
25 # Found a parent section without a uses = part.
26 for heritable in self.options(parent):
27 if not self.has_option(section, heritable):
30 self.get(parent, heritable))
32 self.remove_option(section, "uses")
35 # Sanity check: All items must have a type field.
36 for section in self.sections():
37 if not self.has_option(section, "type"):
38 raise ConfigParser.Error("%s has no type" % section)
39 elif self.get(section, "type") not in ("engine", "vendor", "device"):
40 raise ConfigParser.Error("%s has invalid type" % section)
41 # Sanity check: All devices must point at a vendor object.
42 # Side effect: build the lists of vendors and devices.
45 for section in self.sections():
46 if self.get(section, "type") == "vendor":
47 self.vendors.append(section)
48 if self.get(section, "type") == "device":
49 self.devices.append(section)
51 for section in self.sections():
52 if self.get(section, "type") == "device":
53 if not self.has_option(section, "vendor"):
54 raise ConfigParser.Error("%s has no vendor" % section)
55 if self.get(section, "vendor") not in self.vendors:
56 raise ConfigParser.Error("%s has invalid vendor" % section)
58 def HTMLDump(self, ofp):
59 thead = """<table border='1' style='font-size:small;' bgcolor='#CCCCCC'>
60 <caption>Listing %s devices from %s vendors</caption>
68 <th width='50%%'>Notes</th>
71 vhead = "<tr><td style='text-align:center;' colspan='7'><a href='%s'>%s</a></td></tr>\n"
72 hotpluggables = ("pl2303", "CP2101")
73 ofp.write(thead % (len(self.devices), len(self.vendors)))
74 for vendor in self.vendors:
75 ofp.write(vhead % (self.get(vendor, "vendor_site"), vendor))
77 for dev in self.devices:
78 if self.get(dev, "vendor") == vendor:
83 if self.get(dev, "packaging") == "OEM module":
84 rowcolor = "LimeGreen"
85 elif self.get(dev, "packaging") == "chipset":
86 rowcolor = "LightYellow"
87 elif self.get(dev, "packaging") == "handset":
89 elif self.get(dev, "packaging") == "hansdfree":
92 ofp.write("<tr bgcolor='%s'>\n" % rowcolor)
94 if self.has_option(dev, "techdoc"):
95 namefield = "<a href='%s'>%s</a>" % (self.get(dev, "techdoc"), dev)
96 if self.has_option(dev, "discontinued"):
97 namefield = namefield + " <img title='Device discontinued' src='discontinued.png'/>"
98 ofp.write("<td>%s</td>\n" % namefield)
99 ofp.write("<td>%s</td>\n" % self.get(dev, "packaging"))
100 engine = self.get(dev, "engine")
101 if self.has_option(engine, "techdoc"):
102 engine = "<a href='%s'>%s</a>" % (self.get(engine, "techdoc"), engine)
103 if self.has_option(dev, "subtype"):
104 engine += " (" + self.get(dev, "subtype") + ")"
105 ofp.write("<td>%s</td>\n" % engine)
106 interfaces = self.get(dev, "interfaces")
107 if self.has_option(dev, "pps"):
109 ofp.write("<td>%s</td>\n" % interfaces)
111 if self.has_option(dev, "tested"):
112 tested = self.get(dev, "tested")
113 if tested == "regression":
114 testfield += "<img title='Have regression test' src='regression.png'>"
117 if self.has_option(dev, "noconfigure"):
118 testfield += "<img title='Requires -b option' src='noconfigure.png'>"
119 if self.get(dev, "rating") == "excellent":
120 testfield += "<img src='star.png'/><img src='star.png'/><img src='star.png'/><img src='star.png'/>"
121 elif self.get(dev, "rating") == "good":
122 testfield += "<img src='star.png'/><img src='star.png'/'><img src='star.png'/>"
123 elif self.get(dev, "rating") == "fair":
124 testfield += "<img src='star.png'/><img src='star.png'/>"
125 elif self.get(dev, "rating") == "poor":
126 testfield += "<img src='star.png'/>"
127 elif self.get(dev, "rating") == "broken":
128 testfield += "<img title='Device is broken' src='bomb.png'/>"
129 if self.has_option(dev, "usbchip") and self.get(dev, "usbchip") in hotpluggables:
130 testfield += "<img src='hotplug.png'/>"
131 ofp.write("<td>%s</td>\n" % testfield)
133 if self.has_option(dev, "nmea"):
134 nmea = self.get(dev, "nmea")
135 ofp.write("<td>%s</td>\n" % nmea)
136 if self.has_option(dev, "notes"):
137 notes = self.get(dev, "notes")
140 if self.has_option(dev, "submitter"):
141 notes += " Reported by %s." % self.get(dev, "submitter")
142 notes = notes.replace("@", "@").replace("<", "<").replace(">", ">")
143 ofp.write("<td>%s</td>\n" % notes)
145 ofp.write("</table>\n")
148 if __name__ == "__main__":
151 d.HTMLDump(sys.stdout)