ncp.py 文件源码

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

项目:bellows 作者: rcloran 项目源码 文件源码
def config(ctx, config, all_):
    """Get/set configuration on the NCP"""
    click.secho(
        "NOTE: Configuration changes do not persist across resets",
        fg='red'
    )
    if config and all_:
        raise click.BadOptionUsage("Specify a config or --all, not both")

    if not (config or all_):
        raise click.BadOptionUsage("One of config or --all must be specified")

    s = yield from util.setup(ctx.obj['device'], ctx.obj['baudrate'], util.print_cb)

    if all_:
        for config in t.EzspConfigId:
            v = yield from s.getConfigurationValue(config)
            if v[0] == t.EzspStatus.ERROR_INVALID_ID:
                continue
            click.echo("%s=%s" % (config.name, v[1]))
        s.close()
        return

    if '=' in config:
        config, value = config.split("=", 1)
        if config.isdigit():
            try:
                config = t.EzspConfigId(int(config))
            except ValueError:
                raise click.BadArgumentUsage("Invalid config ID: %s" % (
                    config,
                ))
        else:
            try:
                config = t.EzspConfigId[config]
            except KeyError:
                raise click.BadArgumentUsage("Invalid config name: %s" % (
                    config,
                ))
        try:
            value = t.uint16_t(value)
            if not (0 <= value <= 65535):
                raise ValueError("%s out of allowed range 0..65535" % (
                    value,
                ))
        except ValueError as e:
            raise click.BadArgumentUsage("Invalid value: %s" % (e, ))

        v = yield from s.setConfigurationValue(config, value)
        click.echo(v)
        s.close()
        return

    v = yield from s.getConfigurationValue(config)
    click.echo(v)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号