From 8bba0b88fd9329b44a53fcf43413e78ff2a55a30 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Tue, 15 Sep 2015 02:46:06 -0400 Subject: [PATCH] blocks! --- homeassistant/__main__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index 8166ef583d9..79f5d43ca04 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -163,13 +163,20 @@ def write_pid(pid_file): def install_osx(): """ Setup to run via launchd on OS X """ - hass_path = os.popen('which hass').read().strip() - user = os.popen('whoami').read().strip() + with os.popen('which hass') as inp: + hass_path = inp.read().strip() + + with os.popen('whoami') as inp: + user = inp.read().strip() cwd = os.path.dirname(__file__) template_path = os.path.join(cwd, 'startup', 'launchd.plist') + with open(template_path, 'r', encoding='utf-8') as inp: + plist = inp.read() + plist = codecs.open(template_path, 'r', 'utf-8') + plist = plist.read() plist = plist.replace("$HASS_PATH$", hass_path) @@ -180,9 +187,9 @@ def install_osx(): if os.path.isfile(path): os.remove(path) - plist_file = codecs.open(path, 'w', 'utf-8') - plist_file.write(plist) - plist_file.close() + with codecs.open(path, 'w', 'utf-8') as outp: + outp.write(plist) + os.popen('launchctl load -w -F ' + path) print("Home Assistant has been installed. \