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)
评论列表
文章目录