Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creating directories #39728

Merged
merged 1 commit into from
Sep 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
allow creating directories from camera snapshot, stream record, and t…
…ensorflow file out
  • Loading branch information
hunterjm committed Sep 6, 2020
commit f095040c99c024e17e1938003135e0b6b12debdc
3 changes: 3 additions & 0 deletions homeassistant/components/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import timedelta
import hashlib
import logging
import os
from random import SystemRandom

from aiohttp import web
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/stream/recorder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Provide functionality to record stream."""

import os
import threading
from typing import List

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/tensorflow/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ def _save_image(self, image, matches, paths):

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):
Expand Down