Update ConfigParser: Add option to load file if exists and do nothing otherwise.
--- a/pycolib/configparser.py Mon Apr 14 22:29:07 2014 +0200
+++ b/pycolib/configparser.py Wed May 07 18:37:13 2014 +0200
@@ -1,4 +1,4 @@
-# simple config file parser utilizing Python's exec() builtin
+import os.path
class ConfigParserError(Exception):
@@ -6,6 +6,11 @@
class ConfigParser:
+
+ """
+ Simple config file parser utilizing Python's exec() builtin.
+ """
+
def __init__(self):
self.options = {}
self.values = {}
@@ -15,8 +20,10 @@
self.options[name] = {'type':type, 'default':default}
self.values[name] = default
- def load(self, fname):
+ def load(self, fname, must_exist=True):
"""Read config file and check loaded values."""
+ if not must_exist and not os.path.isfile(fname):
+ return
self.read(fname)
self.check()