__init__.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:satori-rtm-sdk-python 作者: satori-com 项目源码 文件源码
def load_args_from_config_file(path=None):
    quiet = False
    if path is None:
        quiet = True
        path = os.path.join(XDG_CONFIG_HOME, 'satori', 'rtm-cli.config')
    result = {}
    try:
        try:
            with open(path) as f:
                fileconfig = toml.load(f)
                for k, v in fileconfig.items():
                    print(
                        "From config file: {0} = {1}".format(k, v),
                        file=sys.stderr)
                    result[u'--' + k] = v
        except toml.TomlDecodeError:
            try:
                # Just in case the config file has the format credentials.json
                with open(path) as f:
                    fileconfig = json.load(f)
                    for k, v in fileconfig.items():
                        if k == 'auth_role_name':
                            k = 'role_name'
                        if k == 'auth_role_secret_key':
                            k = 'role_secret'
                        print(
                            "From config file: {0} = {1}".format(k, v),
                            file=sys.stderr)
                        result[u'--' + k] = v
            except ValueError:
                print(
                    "Invalid config file at {0}".format(path),
                    file=sys.stderr)
    except (IOError, OSError):
        if not quiet:
            print(
                "Couldn't read the config file at {0}".format(path),
                file=sys.stderr)
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号