Remove unnecessary checks before calling os.makedirs (#62576)
This commit is contained in:
parent
1edfa2d426
commit
cb2c2d98c3
9 changed files with 9 additions and 17 deletions
|
@ -849,8 +849,7 @@ async def async_handle_snapshot_service(
|
|||
"""Executor helper to write image."""
|
||||
if image_data is None:
|
||||
return
|
||||
if not os.path.exists(os.path.dirname(to_file)):
|
||||
os.makedirs(os.path.dirname(to_file), exist_ok=True)
|
||||
os.makedirs(os.path.dirname(to_file), exist_ok=True)
|
||||
with open(to_file, "wb") as img_file:
|
||||
img_file.write(image_data)
|
||||
|
||||
|
|
|
@ -270,8 +270,7 @@ class Doods(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)
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
img.save(path)
|
||||
|
||||
def process_image(self, image):
|
||||
|
|
|
@ -110,8 +110,7 @@ def setup(hass, config):
|
|||
subdir_path = os.path.join(download_path, subdir)
|
||||
|
||||
# Ensure subdir exist
|
||||
if not os.path.isdir(subdir_path):
|
||||
os.makedirs(subdir_path)
|
||||
os.makedirs(subdir_path, exist_ok=True)
|
||||
|
||||
final_path = os.path.join(subdir_path, filename)
|
||||
|
||||
|
|
|
@ -492,8 +492,7 @@ def setup_platform(
|
|||
offset: datetime.timedelta = config[CONF_OFFSET]
|
||||
include_tomorrow = config[CONF_TOMORROW]
|
||||
|
||||
if not os.path.exists(gtfs_dir):
|
||||
os.makedirs(gtfs_dir)
|
||||
os.makedirs(gtfs_dir, exist_ok=True)
|
||||
|
||||
if not os.path.exists(os.path.join(gtfs_dir, data)):
|
||||
_LOGGER.error("The given GTFS data file/folder was not found")
|
||||
|
|
|
@ -34,8 +34,7 @@ def recorder_save_worker(file_out: str, segments: deque[Segment]) -> None:
|
|||
_LOGGER.error("Recording failed to capture anything")
|
||||
return
|
||||
|
||||
if not os.path.exists(os.path.dirname(file_out)):
|
||||
os.makedirs(os.path.dirname(file_out), exist_ok=True)
|
||||
os.makedirs(os.path.dirname(file_out), exist_ok=True)
|
||||
|
||||
pts_adjuster: dict[str, int | None] = {"video": None, "audio": None}
|
||||
output: OutputContainer | None = None
|
||||
|
|
|
@ -327,8 +327,7 @@ 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)
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
img.save(path)
|
||||
|
||||
def process_image(self, image):
|
||||
|
|
|
@ -277,8 +277,7 @@ class Store:
|
|||
|
||||
def _write_data(self, path: str, data: dict) -> None:
|
||||
"""Write the data."""
|
||||
if not os.path.isdir(os.path.dirname(path)):
|
||||
os.makedirs(os.path.dirname(path))
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
|
||||
_LOGGER.debug("Writing data for %s to %s", self.key, path)
|
||||
json_util.save_json(
|
||||
|
|
|
@ -30,7 +30,7 @@ def run(args):
|
|||
# Test if configuration directory exists
|
||||
if not os.path.isdir(config_dir):
|
||||
print("Creating directory", config_dir)
|
||||
os.makedirs(config_dir)
|
||||
os.makedirs(config_dir, exist_ok=True)
|
||||
|
||||
config_path = asyncio.run(async_run(config_dir))
|
||||
print("Configuration file:", config_path)
|
||||
|
|
|
@ -1299,8 +1299,7 @@ async def test_homekit_uses_system_zeroconf(hass, hk_driver, mock_async_zeroconf
|
|||
|
||||
def _write_data(path: str, data: dict) -> None:
|
||||
"""Write the data."""
|
||||
if not os.path.isdir(os.path.dirname(path)):
|
||||
os.makedirs(os.path.dirname(path))
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
json_util.save_json(path, data)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue