mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove Windows workarounds (#64068)
This commit is contained in:
parent
be628a7c4d
commit
b3421cf727
@ -5,7 +5,6 @@ import argparse
|
|||||||
import faulthandler
|
import faulthandler
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@ -265,19 +264,6 @@ def main() -> int:
|
|||||||
"""Start Home Assistant."""
|
"""Start Home Assistant."""
|
||||||
validate_python()
|
validate_python()
|
||||||
|
|
||||||
# Run a simple daemon runner process on Windows to handle restarts
|
|
||||||
if os.name == "nt" and "--runner" not in sys.argv:
|
|
||||||
nt_args = cmdline() + ["--runner"]
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
subprocess.check_call(nt_args)
|
|
||||||
sys.exit(0)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
sys.exit(0)
|
|
||||||
except subprocess.CalledProcessError as exc:
|
|
||||||
if exc.returncode != RESTART_EXIT_CODE:
|
|
||||||
sys.exit(exc.returncode)
|
|
||||||
|
|
||||||
args = get_arguments()
|
args = get_arguments()
|
||||||
|
|
||||||
if args.script is not None:
|
if args.script is not None:
|
||||||
|
@ -260,8 +260,8 @@ CORE_CONFIG_SCHEMA = vol.All(
|
|||||||
|
|
||||||
def get_default_config_dir() -> str:
|
def get_default_config_dir() -> str:
|
||||||
"""Put together the default configuration directory based on the OS."""
|
"""Put together the default configuration directory based on the OS."""
|
||||||
data_dir = os.getenv("APPDATA") if os.name == "nt" else os.path.expanduser("~")
|
data_dir = os.path.expanduser("~")
|
||||||
return os.path.join(data_dir, CONFIG_DIR_NAME) # type: ignore
|
return os.path.join(data_dir, CONFIG_DIR_NAME)
|
||||||
|
|
||||||
|
|
||||||
async def async_ensure_config_exists(hass: HomeAssistant) -> bool:
|
async def async_ensure_config_exists(hass: HomeAssistant) -> bool:
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
"""Signal handling related helpers."""
|
"""Signal handling related helpers."""
|
||||||
import logging
|
import logging
|
||||||
import signal
|
import signal
|
||||||
import sys
|
|
||||||
from types import FrameType
|
|
||||||
|
|
||||||
from homeassistant.const import RESTART_EXIT_CODE
|
from homeassistant.const import RESTART_EXIT_CODE
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -15,57 +13,31 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
@bind_hass
|
@bind_hass
|
||||||
def async_register_signal_handling(hass: HomeAssistant) -> None:
|
def async_register_signal_handling(hass: HomeAssistant) -> None:
|
||||||
"""Register system signal handler for core."""
|
"""Register system signal handler for core."""
|
||||||
if sys.platform != "win32":
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_signal_handle(exit_code: int) -> None:
|
def async_signal_handle(exit_code: int) -> None:
|
||||||
"""Wrap signal handling.
|
"""Wrap signal handling.
|
||||||
|
|
||||||
* queue call to shutdown task
|
* queue call to shutdown task
|
||||||
* re-instate default handler
|
* re-instate default handler
|
||||||
"""
|
"""
|
||||||
hass.loop.remove_signal_handler(signal.SIGTERM)
|
hass.loop.remove_signal_handler(signal.SIGTERM)
|
||||||
hass.loop.remove_signal_handler(signal.SIGINT)
|
hass.loop.remove_signal_handler(signal.SIGINT)
|
||||||
hass.async_create_task(hass.async_stop(exit_code))
|
hass.async_create_task(hass.async_stop(exit_code))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hass.loop.add_signal_handler(signal.SIGTERM, async_signal_handle, 0)
|
hass.loop.add_signal_handler(signal.SIGTERM, async_signal_handle, 0)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning("Could not bind to SIGTERM")
|
_LOGGER.warning("Could not bind to SIGTERM")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hass.loop.add_signal_handler(signal.SIGINT, async_signal_handle, 0)
|
hass.loop.add_signal_handler(signal.SIGINT, async_signal_handle, 0)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning("Could not bind to SIGINT")
|
_LOGGER.warning("Could not bind to SIGINT")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hass.loop.add_signal_handler(
|
hass.loop.add_signal_handler(
|
||||||
signal.SIGHUP, async_signal_handle, RESTART_EXIT_CODE
|
signal.SIGHUP, async_signal_handle, RESTART_EXIT_CODE
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning("Could not bind to SIGHUP")
|
_LOGGER.warning("Could not bind to SIGHUP")
|
||||||
|
|
||||||
else:
|
|
||||||
old_sigterm = None
|
|
||||||
old_sigint = None
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def async_signal_handle(exit_code: int, frame: FrameType) -> None:
|
|
||||||
"""Wrap signal handling.
|
|
||||||
|
|
||||||
* queue call to shutdown task
|
|
||||||
* re-instate default handler
|
|
||||||
"""
|
|
||||||
signal.signal(signal.SIGTERM, old_sigterm)
|
|
||||||
signal.signal(signal.SIGINT, old_sigint)
|
|
||||||
hass.async_create_task(hass.async_stop(exit_code))
|
|
||||||
|
|
||||||
try:
|
|
||||||
old_sigterm = signal.signal(signal.SIGTERM, async_signal_handle)
|
|
||||||
except ValueError:
|
|
||||||
_LOGGER.warning("Could not bind to SIGTERM")
|
|
||||||
|
|
||||||
try:
|
|
||||||
old_sigint = signal.signal(signal.SIGINT, async_signal_handle)
|
|
||||||
except ValueError:
|
|
||||||
_LOGGER.warning("Could not bind to SIGINT")
|
|
||||||
|
@ -34,9 +34,7 @@ async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
info_object["user"] = None
|
info_object["user"] = None
|
||||||
|
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Darwin":
|
||||||
info_object["os_version"] = platform.win32_ver()[0]
|
|
||||||
elif platform.system() == "Darwin":
|
|
||||||
info_object["os_version"] = platform.mac_ver()[0]
|
info_object["os_version"] = platform.mac_ver()[0]
|
||||||
elif platform.system() == "Linux":
|
elif platform.system() == "Linux":
|
||||||
info_object["docker"] = os.path.isfile("/.dockerenv")
|
info_object["docker"] = os.path.isfile("/.dockerenv")
|
||||||
|
@ -89,10 +89,9 @@ def install_package(
|
|||||||
# This only works if not running in venv
|
# This only works if not running in venv
|
||||||
args += ["--user"]
|
args += ["--user"]
|
||||||
env["PYTHONUSERBASE"] = os.path.abspath(target)
|
env["PYTHONUSERBASE"] = os.path.abspath(target)
|
||||||
if sys.platform != "win32":
|
# Workaround for incompatible prefix setting
|
||||||
# Workaround for incompatible prefix setting
|
# See http://stackoverflow.com/a/4495175
|
||||||
# See http://stackoverflow.com/a/4495175
|
args += ["--prefix="]
|
||||||
args += ["--prefix="]
|
|
||||||
_LOGGER.debug("Running pip command: args=%s", args)
|
_LOGGER.debug("Running pip command: args=%s", args)
|
||||||
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) as process:
|
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) as process:
|
||||||
_, stderr = process.communicate()
|
_, stderr = process.communicate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user