From 0d8e86265f74ee36503bbcec445dcefdea208df0 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 13 Feb 2012 22:09:11 +0100 Subject: Initial import. --- config.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 config.py (limited to 'config.py') diff --git a/config.py b/config.py new file mode 100644 index 0000000..3f8995b --- /dev/null +++ b/config.py @@ -0,0 +1,25 @@ +try: + from configparser import ConfigParser, NoOptionError +except ImportError: + from ConfigParser import ConfigParser, NoOptionError + +class Config(object): + config_section = 'ongaku' + + def __init__(self, filename = 'config'): + self.config = ConfigParser() + self.config.read(filename) + + def get(self, key, section = config_section, default = None): + try: + return self.config.get(section, key) + except NoOptionError: + if default != None: + return default + else: + raise + + def getint(self, key, section = config_section): + return self.config.getint(section, key) + +config = Config() -- cgit v1.2.3