Ejemplo n.º 1
0
    def __init__(self, module, env=None):
        """Initialize the Environment object
		:param module: The Module that serves as the basis for this botoweb application
		:param env: Optional environment file that overrides any settings in our config
		"""
        self.module = module
        self._client_connection = None
        if not env:
            env = os.environ.get("BOTO_WEB_ENV")
        self.env = env

        # Config setup
        self.config = Config()
        self.config.env = self

        self.dist = get_provider(self.module)
        self.mgr = ResourceManager()

        if self.dist.has_resource("conf"):
            self.config.update(self.get_config("conf"))

        if env and os.path.exists(self.env):
            log.info("Loading environment: %s" % self.env)
            self.config.update(yaml.load(open(self.env, "r")))

        # Set up the DB shortcuts
        if not self.config.has_key("DB"):
            self.config['DB'] = {
                "db_type":
                self.config.get("DB", "db_type", "SimpleDB"),
                "db_user":
                self.config.get("Credentials", "aws_access_key_id"),
                "db_passwd":
                self.config.get("Credentials", "aws_secret_access_key")
            }
        if self.config.has_key("auth_db"):
            self.config['DB']['User'] = {"db_name": self.config['auth_db']}
        if self.config.has_key("default_db"):
            self.config['DB']['db_name'] = self.config["default_db"]
        if self.config.has_key("session_db"):
            self.config['DB']['Session'] = {
                'db_name': self.config["session_db"]
            }

        # Bootstrap importing all db_classes for XMLize
        if self.config['botoweb'].has_key("handlers"):
            for handler in self.config['botoweb']['handlers']:
                if handler.has_key("db_class"):
                    try:
                        db_class = find_class(handler['db_class'])
                    except:
                        log.exception("Could not load class: %s" %
                                      handler['db_class'])
                        db_class = None
                    if db_class:
                        xmlize.register(db_class)