Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (34 sloc) 1.31 KB
from ConfigParser import RawConfigParser, NoOptionError
plugin_prefix = "harold:plugin:"
NoDefault = object()
class HaroldConfiguration(object):
def __init__(self, filenames):
self.parser = RawConfigParser()
def plugin_names(self):
for section in self.parser.sections():
if not section.startswith(plugin_prefix):
yield section[len(plugin_prefix):]
class Option(object):
def __init__(self, convert, default=NoDefault):
self.convert = convert
self.default = default
def tup(option):
return [x.strip() for x in option.split(',') if x]
class PluginConfig(object):
def __init__(self, config, section=None):
if not section:
plugin_name = self.__module__[len("harold.plugins."):]
section = plugin_prefix + plugin_name
for name, contents in vars(type(self)).iteritems():
if not isinstance(contents, Option):
value = config.parser.get(section, name)
value = contents.convert(value)
except NoOptionError:
if contents.default is NoDefault:
value = contents.default
setattr(self, name, value)
Something went wrong with that request. Please try again.