MCPcopy
hub / github.com/hacs/integration / _write_file

Method _write_file

custom_components/hacs/base.py:434–457  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

432 """Save a file."""
433
434 def _write_file():
435 with open(
436 file_path,
437 mode="w" if isinstance(content, str) else "wb",
438 encoding="utf-8" if isinstance(content, str) else None,
439 errors="ignore" if isinstance(content, str) else None,
440 ) as file_handler:
441 file_handler.write(content)
442
443 # Create gz for .js files
444 if os.path.isfile(file_path):
445 if file_path.endswith(".js"):
446 with open(file_path, "rb") as f_in:
447 with gzip.open(file_path + ".gz", "wb") as f_out:
448 shutil.copyfileobj(f_in, f_out)
449
450 # LEGACY! Remove with 2.0
451 if "themes" in file_path and file_path.endswith(".yaml"):
452 filename = file_path.split("/")[-1]
453 base = file_path.split("/themes/")[0]
454 combined = f"{base}/themes/{filename}"
455 if os.path.exists(combined):
456 self.log.info("Removing old theme file %s", combined)
457 os.remove(combined)
458
459 try:
460 await self.hass.async_add_executor_job(_write_file)

Callers

nothing calls this directly

Calls 1

removeMethod · 0.80

Tested by

no test coverage detected