#!/usr/bin/env python2
# vim:fenc=utf-8:ts=8:et:sw=4:sts=4:tw=79:ft=python

"""
config.py

The PearBot IRC bot configuration loader.
It reads configuratiom from environment variables and provides access to
component specific dictionaries.

Copyright (c) 2014 Twisted Pear <pear at twistedpear dot at>
See the file LICENSE for copying permission.
"""

from os import environ


def __get_irc_config():
    """Get a configuration dictionary for IRC specific settings."""
    channel_list = environ["PEARBOT_IRC_CHANNELS"]
    channels = channel_list.split(";")

    return {"hostname": environ["PEARBOT_IRC_HOSTNAME"],
            "port": environ["PEARBOT_IRC_PORT"],
            "ssl": True if "PEARBOT_IRC_SSL" in environ else False,
            "password": environ.get("PEARBOT_IRC_PASSWORD"),
            "nickname": environ["PEARBOT_IRC_NICKNAME"],
            "username": environ["PEARBOT_IRC_USERNAME"],
            "realname": environ["PEARBOT_IRC_REALNAME"],
            "channels": channels}


def __get_cmd_config():
    """Get a configuration dictionary for a CommandHandler instance."""

    return {"prefix": environ.get("PEARBOT_CMD_PREFIX", "!")}


def get_config(component):
    """
    Get a configuration dictionary for a specific component.
    Valid components are:
    - irc
    """
    if component == "irc":
        return __get_irc_config()
    elif component == "cmd":
        return __get_cmd_config()

    # we don't know that config
    raise KeyError("No such component: {0}".format(component))

@@ -629,16 +629,20 @@
 %22port%22: 
+int(
 environ%5B
@@ -660,16 +660,17 @@
 C_PORT%22%5D
+)
 ,%0A      
@@ -1156,24 +1156,187 @@
 X%22, %22!%22)%7D%0A%0A%0A
+def __get_rss_config():%0A    %22%22%22Get a configuration dictionary for a LRRFeedParser instance.%22%22%22%0A%0A    return %7B%22delay%22: int(environ.get(%22PEARBOT_RSS_DELAY%22, 300))%7D%0A%0A%0A
 def get_conf
@@ -1553,16 +1553,16 @@
  %22cmd%22:%0A
-
         
@@ -1586,16 +1586,79 @@
 config()
+%0A    elif component == %22rss%22:%0A        return __get_rss_config()
 %0A%0A    # 

Add config options for RSS feed parser