# HG changeset patch # User Radek Brich # Date 1399480633 -7200 # Node ID d5f749032fa18e51207faf131c8c6c01ccc7d76a # Parent d1f08fc9de31cf745c9011f4b6483813af5bab49 Update ConfigParser: Add option to load file if exists and do nothing otherwise. diff -r d1f08fc9de31 -r d5f749032fa1 pycolib/configparser.py --- 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()