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 from datetime import timedelta
import hashlib import hashlib
import logging import logging
import os
from random import SystemRandom from random import SystemRandom
from aiohttp import web from aiohttp import web
@ -660,6 +661,8 @@ async def async_handle_snapshot_service(camera, service):
def _write_image(to_file, image_data): def _write_image(to_file, image_data):
"""Executor helper to write image.""" """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: with open(to_file, "wb") as img_file:
img_file.write(image_data) img_file.write(image_data)

View File

@ -1,5 +1,5 @@
"""Provide functionality to record stream.""" """Provide functionality to record stream."""
import os
import threading import threading
from typing import List 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): def recorder_save_worker(file_out: str, segments: List[Segment], container_format: str):
"""Handle saving stream.""" """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} first_pts = {"video": None, "audio": None}
output = av.open(file_out, "w", format=container_format) output = av.open(file_out, "w", format=container_format)
output_v = None output_v = None

View File

@ -328,6 +328,8 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
for path in paths: for path in paths:
_LOGGER.info("Saving results image to %s", path) _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) img.save(path)
def process_image(self, image): def process_image(self, image):