Skip to content

Instantly share code, notes, and snippets.

@pauricthelodger
Last active December 16, 2015 22:20
Show Gist options
  • Save pauricthelodger/9eb6730bb74213c79dff to your computer and use it in GitHub Desktop.
Save pauricthelodger/9eb6730bb74213c79dff to your computer and use it in GitHub Desktop.
class ConfigRuleset(dict):
defaults = {
'name': 'no name',
}
required = [
'name',
]
def __init__(self):
self.update(self.defaults)
def validate(self):
missing = []
for key in self.required:
if not self.has_key(key):
missing.append(key)
if len(missing):
raise KeyError("The following required config keys are missing: %s" % missing)
class ConfigProvider(ConfigRuleset):
src = None
prop = re.compile(r"([\w. ]+)\s*=\s*(.*)")
def __init__(self, source = "config.properties"):
ConfigRuleset.__init__(self)
self.src = source
self.loadConfig()
self.validate()
….
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment