# vim: ts=4 et sts=4 sw=4 autoindent

from ConfigParser import RawConfigParser, NoSectionError, NoOptionError
import sys,os

from sndcs_common.Logger import logger
log = logger.getLogger("Config")

class Config(object):

    def __init__(self, filenames):
        self.config = RawConfigParser() # Use RawConfigParser because we don't want the magical interpolation behavior
        self.parsed_filenames = self.config.read(filenames)

    def read(self, filenames):
        parsed  = self.config.read(filenames)
        self.parsed_filenames += parsed
        return parsed

    def get(self, section, parameter, default = None):
        """
        Get value from config file.
        If the section and/or parameter doesn't exist return the default.
        """
        try:
            value = self.config.get(section, parameter)
        except (NoSectionError, NoOptionError):
            log.info("'Section: %s, Parameter: %s' not found in config, using default value: %s" % (section,parameter,default))
            return default

        return value

    def getParsedFilenames(self):
        """ Return list of config files that ConfigParser was able to use """
        return self.parsed_filenames
