""" 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 = """ """ vhead = "\n" ofp.write(thead % (len(self.devices), len(self.vendors))) 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.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") == "hansdfree": rowcolor = "DarkCyan" ofp.write("\n" % rowcolor) namefield = dev if self.has_option(dev, "reference"): namefield = "%s" % (self.get(dev, "reference"), dev) if self.has_option(dev, "discontinued"): namefield = namefield + " " ofp.write("\n" % namefield) ofp.write("\n" % self.get(dev, "packaging")) engine = self.get(dev, "engine") if self.has_option(engine, "reference"): engine = "%s" % (self.get(engine, "reference"), engine) if self.has_option(dev, "subtype"): engine += " (" + self.get(dev, "subtype") + ")" ofp.write("\n" % engine) interfaces = self.get(dev, "interfaces") if self.has_option(dev, "pps"): interfaces += ",PPS" ofp.write("\n" % interfaces) testfield = "" if self.has_option(dev, "tested"): tested = self.get(dev, "tested") if tested == "regression": testfield += "" else: testfield += tested if self.has_option(dev, "noconfigure"): testfield += "" if self.get(dev, "status") == "excellent": testfield += "" elif self.get(dev, "status") == "good": testfield += "" elif self.get(dev, "status") == "fair": testfield += "" elif self.get(dev, "status") == "poor": testfield += "" elif self.get(dev, "status") == "broken": testfield += "" ofp.write("\n" % testfield) nmea = " " if self.has_option(dev, "nmea"): nmea = self.get(dev, "nmea") ofp.write("\n" % nmea) ofp.write("\n" % self.get(dev, "notes")) ofp.write("\n") ofp.write("
Listing %s devices from %s vendors
Name Packaging Engine Interface Tested with NMEA version Notes
%s
%s%s%s%s%s%s%s
\n") if __name__ == "__main__": import sys d = GPSDictionary() d.HTMLDump(sys.stdout)