summaryrefslogtreecommitdiff
path: root/gpscap.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-01-19 19:36:26 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-01-19 19:36:26 +0000
commita05b5ba9ef5a443c4dede52702048038ee0bf95c (patch)
tree29d83e52fc5af04c263b3d0729df430df38e4b4b /gpscap.py
parent97a472a1c63c728a7d72aba5c4564f30587a448e (diff)
downloadgpsd-a05b5ba9ef5a443c4dede52702048038ee0bf95c.tar.gz
Part-conversion of hardware reference page to capability database...
..and a Python wrapper class that parses it.
Diffstat (limited to 'gpscap.py')
-rw-r--r--gpscap.py35
1 files changed, 35 insertions, 0 deletions
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()