aboutsummaryrefslogtreecommitdiffstats
path: root/confparser.py
diff options
context:
space:
mode:
authorVG <vg@devys.org>2015-12-11 14:56:40 +0100
committerVG <vg@devys.org>2015-12-11 14:56:40 +0100
commitc14ad43f8c6ba9cabe1bb11cad859c8da6dc54ca (patch)
tree4ddd7e515959389200eb9bab6d9fc31c4cd554ff /confparser.py
parent72789b40ca9b2f7ebe05f4a298309cb0c1bf8a63 (diff)
downloadcliml-c14ad43f8c6ba9cabe1bb11cad859c8da6dc54ca.tar.gz
climl-c14ad43f8c6ba9cabe1bb11cad859c8da6dc54ca.tar.bz2
climl-c14ad43f8c6ba9cabe1bb11cad859c8da6dc54ca.zip
include a custom conf parser
Diffstat (limited to 'confparser.py')
-rw-r--r--confparser.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/confparser.py b/confparser.py
new file mode 100644
index 0000000..e43443b
--- /dev/null
+++ b/confparser.py
@@ -0,0 +1,27 @@
+#!python3
+
+__all__ = ['read_conf']
+
+import csv
+
+class conf_dialect(csv.Dialect):
+ delimiter = '='
+ quotechar = '"'
+ escapechar = '\\'
+ doublequote = True
+ skipinitialspace = True
+ lineterminator = '\n'
+ quoting = csv.QUOTE_MINIMAL
+
+def genestrip(geneorg):
+ for line in geneorg:
+ line = line.strip()
+ if not len(line) or line.startswith('#'):
+ continue
+ yield line
+
+def read_conf(filename):
+ with open(filename, 'r', encoding='utf8') as linegen:
+ reader = csv.reader(genestrip(linegen), dialect=conf_dialect)
+ dic = {row[0].strip(): row[1] for row in reader if len(row) >= 2}
+ return dic