Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -5,17 +5,18 @@ import time
|
||||
|
||||
# mypy: allow-untyped-calls, allow-untyped-defs
|
||||
|
||||
|
||||
def install_osx():
|
||||
"""Set up to run via launchd on OS X."""
|
||||
with os.popen('which hass') as inp:
|
||||
with os.popen("which hass") as inp:
|
||||
hass_path = inp.read().strip()
|
||||
|
||||
with os.popen('whoami') as inp:
|
||||
with os.popen("whoami") as inp:
|
||||
user = inp.read().strip()
|
||||
|
||||
template_path = os.path.join(os.path.dirname(__file__), 'launchd.plist')
|
||||
template_path = os.path.join(os.path.dirname(__file__), "launchd.plist")
|
||||
|
||||
with open(template_path, 'r', encoding='utf-8') as inp:
|
||||
with open(template_path, "r", encoding="utf-8") as inp:
|
||||
plist = inp.read()
|
||||
|
||||
plist = plist.replace("$HASS_PATH$", hass_path)
|
||||
@@ -24,40 +25,42 @@ def install_osx():
|
||||
path = os.path.expanduser("~/Library/LaunchAgents/org.homeassistant.plist")
|
||||
|
||||
try:
|
||||
with open(path, 'w', encoding='utf-8') as outp:
|
||||
with open(path, "w", encoding="utf-8") as outp:
|
||||
outp.write(plist)
|
||||
except IOError as err:
|
||||
print('Unable to write to ' + path, err)
|
||||
print("Unable to write to " + path, err)
|
||||
return
|
||||
|
||||
os.popen('launchctl load -w -F ' + path)
|
||||
os.popen("launchctl load -w -F " + path)
|
||||
|
||||
print("Home Assistant has been installed. \
|
||||
Open it here: http://localhost:8123")
|
||||
print(
|
||||
"Home Assistant has been installed. \
|
||||
Open it here: http://localhost:8123"
|
||||
)
|
||||
|
||||
|
||||
def uninstall_osx():
|
||||
"""Unload from launchd on OS X."""
|
||||
path = os.path.expanduser("~/Library/LaunchAgents/org.homeassistant.plist")
|
||||
os.popen('launchctl unload ' + path)
|
||||
os.popen("launchctl unload " + path)
|
||||
|
||||
print("Home Assistant has been uninstalled.")
|
||||
|
||||
|
||||
def run(args):
|
||||
"""Handle OSX commandline script."""
|
||||
commands = 'install', 'uninstall', 'restart'
|
||||
commands = "install", "uninstall", "restart"
|
||||
if not args or args[0] not in commands:
|
||||
print('Invalid command. Available commands:', ', '.join(commands))
|
||||
print("Invalid command. Available commands:", ", ".join(commands))
|
||||
return 1
|
||||
|
||||
if args[0] == 'install':
|
||||
if args[0] == "install":
|
||||
install_osx()
|
||||
return 0
|
||||
if args[0] == 'uninstall':
|
||||
if args[0] == "uninstall":
|
||||
uninstall_osx()
|
||||
return 0
|
||||
if args[0] == 'restart':
|
||||
if args[0] == "restart":
|
||||
uninstall_osx()
|
||||
# A small delay is needed on some systems to let the unload finish.
|
||||
time.sleep(0.5)
|
||||
|
||||
Reference in new issue
Block a user