allow creating directories from camera snapshot, stream record, and tensorflow file out (#39728)

This commit is contained in:
Jason Hunter 2020-09-06 18:54:24 -04:00 committed by GitHub
parent 1ec3446c56
commit 1a78d96014
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View file

@ -6,6 +6,7 @@ from contextlib import suppress
from datetime import timedelta
import hashlib
import logging
import os
from random import SystemRandom
from aiohttp import web
@ -660,6 +661,8 @@ async def async_handle_snapshot_service(camera, service):
def _write_image(to_file, image_data):
"""Executor helper to write image."""
if not os.path.exists(os.path.dirname(to_file)):
os.makedirs(os.path.dirname(to_file), exist_ok=True)
with open(to_file, "wb") as img_file:
img_file.write(image_data)

View file

@ -1,5 +1,5 @@
"""Provide functionality to record stream."""
import os
import threading
from typing import List
@ -17,6 +17,9 @@ def async_setup_recorder(hass):
def recorder_save_worker(file_out: str, segments: List[Segment], container_format: str):
"""Handle saving stream."""
if not os.path.exists(os.path.dirname(file_out)):
os.makedirs(os.path.dirname(file_out), exist_ok=True)
first_pts = {"video": None, "audio": None}
output = av.open(file_out, "w", format=container_format)
output_v = None

View file

@ -328,6 +328,8 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
for path in paths:
_LOGGER.info("Saving results image to %s", path)
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path), exist_ok=True)
img.save(path)
def process_image(self, image):