aboutsummaryrefslogtreecommitdiffstats
path: root/confparser/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'confparser/__init__.py')
-rw-r--r--confparser/__init__.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/confparser/__init__.py b/confparser/__init__.py
new file mode 100644
index 0000000..e43443b
--- /dev/null
+++ b/confparser/__init__.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