1 """Home Assistant command line scripts."""
3 from __future__
import annotations
7 from collections.abc
import Sequence
13 from homeassistant
import runner
22 def run(args: list[str]) -> int:
25 path = os.path.dirname(__file__)
26 for fil
in os.listdir(path):
27 if fil ==
"__pycache__":
30 if os.path.isdir(os.path.join(path, fil)):
32 elif fil !=
"__init__.py" and fil.endswith(
".py"):
33 scripts.append(fil[:-3])
36 print(
"Please specify a script to run.")
37 print(
"Available scripts:",
", ".join(scripts))
40 if args[0]
not in scripts:
41 print(
"Invalid script specified.")
42 print(
"Available scripts:",
", ".join(scripts))
45 script = importlib.import_module(f
"homeassistant.scripts.{args[0]}")
49 loop = asyncio.get_event_loop()
56 logging.basicConfig(stream=sys.stdout, level=logging.INFO)
58 for req
in getattr(script,
"REQUIREMENTS", []):
63 print(
"Aborting script, could not install dependency", req)
68 return script.run(args[1:])
72 """Extract the config dir from the arguments or get the default."""
73 parser = argparse.ArgumentParser(add_help=
False)
74 parser.add_argument(
"-c",
"--config", default=
None)
75 parsed_args = parser.parse_known_args(args)[0]
77 os.path.join(os.getcwd(), parsed_args.config)
str async_mount_local_lib_path(str config_dir)
str get_default_config_dir()
dict[str, Any] pip_kwargs(str|None config_dir)
str extract_config_dir(Sequence[str]|None args=None)
bool is_installed(str requirement_str)
bool install_package(str package, bool upgrade=True, str|None target=None, str|None constraints=None, int|None timeout=None)