Last active
December 16, 2015 22:20
-
-
Save pauricthelodger/9eb6730bb74213c79dff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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