Exemplo n.º 1
0
    def discover_config(self):
        directory = os.path.dirname(os.path.abspath('.') + '/')
        name = 'chameleon_conf'
        config = None
        while config is None and directory:
            config = utils.dict_from_module(
                os.path.join(directory, name))
            directory = directory.rsplit(os.sep, 1)[0]

        return config
Exemplo n.º 2
0
    def __init__(self, config=None):
        """
        if config is None => search filesystem tree up for 'chameleon_conf'
        module
        if config is string => load from file
        if config is kwargs => use it

        All keys from config go to MySQLdb.connect method.
        """
        if config is None:
            config = self.discover_config()

        if isinstance(config, str):
            config = utils.dict_from_module(config)

        if config is None:
            raise ConfigNotFoundException()

        self.config = config
        self.connect()