async def delete_area(area_id: str, reboot_processor: Optional[bool] = True): """ Deletes the configuration related to the area <area_id> """ if area_id.upper() == ALL_AREAS: delete_area_occupancy_rules(ALL_AREAS) raise HTTPException( status_code=status.HTTP_202_ACCEPTED, detail="Area with ID: 'ALL' cannot be deleted. However, its occupancy rules were deleted." ) config_dict = extract_config() areas_name = [x for x in config_dict.keys() if x.startswith("Area_")] areas = [map_section_from_config(x, config_dict) for x in areas_name] areas_ids = [area["id"] for area in areas] try: index = areas_ids.index(area_id) except ValueError: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"The area: {area_id} does not exist") config_dict.pop(f"Area_{index}") config_dict = reestructure_areas(config_dict) success = update_config(config_dict, reboot_processor) delete_area_occupancy_rules(area_id) area_directory = os.path.join(os.getenv("AreaLogDirectory"), area_id) shutil.rmtree(area_directory) area_config_directory = os.path.join(os.getenv("AreaConfigDirectory"), area_id) shutil.rmtree(area_config_directory) return handle_response(None, success, status.HTTP_204_NO_CONTENT)
async def delete_area(area_id: str, reboot_processor: Optional[bool] = True): """ Deletes the configuration related to the area <area_id> """ if area_id.upper() == ALL_AREAS: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=bad_request_serializer( "Area with ID: 'ALL' cannot be deleted.", error_type="Invalid ID")) config_dict = extract_config() areas_name = [x for x in config_dict.keys() if x.startswith("Area_")] areas = [map_section_from_config(x, config_dict) for x in areas_name] areas_ids = [area["id"] for area in areas] try: index = areas_ids.index(area_id) except ValueError: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"The area: {area_id} does not exist") config_dict.pop(f"Area_{index}") config_dict = reestructure_areas((config_dict)) success = update_config(config_dict, reboot_processor) area_directory = os.path.join(os.getenv("AreaLogDirectory"), area_id) shutil.rmtree(area_directory) return handle_response(None, success, status.HTTP_204_NO_CONTENT)
def delete_camera_from_areas(camera_id, config_dict): areas = {key: config_dict[key] for key in config_dict.keys() if key.startswith("Area_")} for key, area in areas.items(): cameras = area["Cameras"].split(",") if camera_id in cameras: cameras.remove(camera_id) if len(cameras) == 0: logger.warning(f'After removing the camera "{camera_id}", the area "{area["Id"]} - {area["Name"]}" \ "was left with no cameras and deleted') config_dict.pop(key) else: config_dict[key]["Cameras"] = ",".join(cameras) config_dict = reestructure_areas(config_dict) return config_dict
async def delete_area(area_id: str, reboot_processor: Optional[bool] = True): """ Deletes the configuration related to the area <area_id> """ config_dict = extract_config() areas_name = [x for x in config_dict.keys() if x.startswith("Area_")] areas = [map_section_from_config(x, config_dict) for x in areas_name] areas_ids = [area["id"] for area in areas] try: index = areas_ids.index(area_id) except ValueError: raise HTTPException(status_code=404, detail=f"The area: {area_id} does not exist") config_dict.pop(f"Area_{index}") config_dict = reestructure_areas((config_dict)) success = update_config(config_dict, reboot_processor) return handle_response(None, success, status.HTTP_204_NO_CONTENT)