From c288fb6cc7e3e3c34461bcfe8b735745a91b32a8 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 20 Jan 2009 02:23:52 +0000 Subject: Add some sanity checks in the wrapper class, and tweak the DB so it passes. --- gpscap.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'gpscap.py') diff --git a/gpscap.py b/gpscap.py index 689fbdf6..7cb44812 100644 --- a/gpscap.py +++ b/gpscap.py @@ -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() -- cgit v1.2.1