diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-01-20 02:23:52 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-01-20 02:23:52 +0000 |
commit | c288fb6cc7e3e3c34461bcfe8b735745a91b32a8 (patch) | |
tree | d8c3cc09eb913ca71bed1a57cf0a401177284f0a /gpscap.py | |
parent | 1d1151cae49fe6ebd0b1e66ea3ecf41227859394 (diff) | |
download | gpsd-c288fb6cc7e3e3c34461bcfe8b735745a91b32a8.tar.gz |
Add some sanity checks in the wrapper class, and tweak the DB so it passes.
Diffstat (limited to 'gpscap.py')
-rw-r--r-- | gpscap.py | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -30,6 +30,24 @@ class GPSDictionary(ConfigParser.RawConfigParser): 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 list of vendors. + self.vendors = [] + for section in self.sections(): + if self.get(section, "type") == "vendor": + self.vendors.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) if __name__ == "__main__": d = GPSDictionary() |