From a05b5ba9ef5a443c4dede52702048038ee0bf95c Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 19 Jan 2009 19:36:26 +0000 Subject: Part-conversion of hardware reference page to capability database... ..and a Python wrapper class that parses it. --- gpscap.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 gpscap.py (limited to 'gpscap.py') diff --git a/gpscap.py b/gpscap.py new file mode 100644 index 00000000..689fbdf6 --- /dev/null +++ b/gpscap.py @@ -0,0 +1,35 @@ +""" + +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 + +if __name__ == "__main__": + d = GPSDictionary() -- cgit v1.2.1