nuimo_components.py 文件源码

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

项目:senic-hub 作者: getsenic 项目源码 文件源码
def delete_nuimo_component_view(request):
    component_id = request.matchdict['component_id']
    mac_address = request.matchdict['mac_address'].replace('-', ':')
    with open(request.registry.settings['nuimo_app_config_path'], 'r+') as f:
        config = yaml.load(f)

        try:
            nuimo = config['nuimos'][mac_address]
        except (KeyError, TypeError):
            return HTTPNotFound("No Nuimo with such ID")

        components = nuimo['components']

        try:
            component = next(c for c in components if c['id'] == component_id)
        except StopIteration:
            raise HTTPNotFound

        components.remove(component)

        f.seek(0)  # We want to overwrite the config file with the new configuration
        f.truncate()
        yaml.dump(config, f, default_flow_style=False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号