'Updates the given defaults with values from the config files and
the environ. Does a little special handling for certain types of
options (lists).'

def update_defaults(self, defaults):

    config = {}
    for section in ('global', self.name):
        config.update(dict(self.get_config_section(section)))
    config.update(dict(self.get_environ_vars()))
    for (key, val) in config.items():
        key = key.replace('_', '-')
        if (not key.startswith('--')):
            key = ('--%s' % key)
        option = self.get_option(key)
        if (option is not None):
            if (not val):
                continue
            if (option.action == 'append'):
                val = val.split()
            else:
                option.nargs = 1
            if (option.action in ('store_true', 'store_false', 'count')):
                val = strtobool(val)
            try:
                val = option.convert_value(key, val)
            except optparse.OptionValueError:
                e = sys.exc_info()[1]
                print ('An    error    occured    during    configuration:    %s' % e)
                sys.exit(3)
            defaults[option.dest] = val
    return defaults
