""" gpscap - GPS/AIS capability dictionary class. This file is Copyright (c) 2010 by the GPSD project SPDX-License-Identifier: BSD-2-clause """ # This code runs compatibly under Python 2 and 3.x for x >= 2. # Preserve this property! from __future__ import absolute_import, print_function, division try: import configparser except ImportError: import ConfigParser as 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"] try: self.read(files, encoding='utf-8') except TypeError: self.read(files) # For Python 2.6 # 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 = """ """ vhead1 = "\n" vhead2 = "\n" hotpluggables = ("pl2303", "CP2101") ofp.write(thead % (len(self.devices), len(self.vendors))) for vendor in self.vendors: if self.has_option(vendor, "notes"): ofp.write(vhead2 % (self.get(vendor, "vendor_site"), vendor, self.get(vendor, "notes"))) else: ofp.write(vhead1 % (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 = "white" if self.get(dev, "packaging") == "OEM module": rowcolor = "#32CD32" elif self.get(dev, "packaging") == "chipset": rowcolor = "#FFFFE0" elif self.get(dev, "packaging") == "handset": rowcolor = "#00FFFF" elif self.get(dev, "packaging") == "hansdfree": rowcolor = "#008B8B" ofp.write("\n" % rowcolor) namefield = dev if self.has_option(dev, "techdoc"): namefield = "%s" \ % (self.get(dev, "techdoc"), dev) if ((self.has_option(dev, "discontinued") and self.getboolean(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, "techdoc"): engine = "%s" \ % (self.get(engine, "techdoc"), 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, "configurable") and self.get(dev, "configurable") == 'insane')): testfield += "" if self.get(dev, "rating") == "excellent": testfield += "Star icon" \ "Star icon" \ "Star icon" \ "Star icon" elif self.get(dev, "rating") == "good": testfield += "Star icon" \ "Star icon" \ "Star icon" elif self.get(dev, "rating") == "fair": testfield += "Star icon" \ "Star icon" elif self.get(dev, "rating") == "poor": testfield += "Star icon" elif self.get(dev, "rating") == "broken": testfield += "Bomb icon" if ((self.has_option(dev, "usbchip") and self.get(dev, "usbchip") in hotpluggables)): testfield += "Hotplug icon" ofp.write("\n" % testfield) nmea = " " if self.has_option(dev, "nmea"): nmea = self.get(dev, "nmea") ofp.write("\n" % nmea) if ((self.has_option(dev, "pps") and self.get(dev, "pps") == "True")): pps_accuracy = time_offset = "" if self.has_option(dev, "pps_accuracy"): pps_accuracy = self.get(dev, "pps_accuracy") if self.has_option(dev, "time_offset"): time_offset = self.get(dev, "time_offset") if pps_accuracy and time_offset: ofp.write("\n" % (pps_accuracy, time_offset)) else: ofp.write("\n") if self.has_option(dev, "notes"): notes = self.get(dev, "notes") else: notes = "" if self.has_option(dev, "submitter"): notes += " Reported by %s." % self.get( dev, "submitter").replace("@", "@").replace( "<", "<").replace(">", ">") ofp.write("\n" % notes) ofp.write("\n") ofp.write("
Listing %s devices from %s vendors
Name Packaging Engine Interface Tested with NMEA version PPS Notes
" \ "%s
" \ "%s

%s

%s%s%s%s%s%s%s
%s
?
\n") else: ofp.write("
No%s
\n") if __name__ == "__main__": import sys try: d = GPSDictionary() d.HTMLDump(sys.stdout) except configparser.Error as e: sys.stderr.write(sys.argv[0] + ":%s\n" % e) raise SystemExit(1)