From a5a1f30798092fbd8d1d1bca897e700dae0bd07e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 29 Aug 2015 23:02:07 -0700 Subject: [PATCH] Make launch more smooth --- homeassistant/__main__.py | 32 +++++++------------------------- homeassistant/bootstrap.py | 9 ++++++--- homeassistant/config.py | 7 +++---- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index 815404b1de1..48232077e75 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -4,32 +4,12 @@ from __future__ import print_function import sys import os import argparse -import importlib from homeassistant import bootstrap import homeassistant.config as config_util from homeassistant.const import EVENT_HOMEASSISTANT_START -def validate_python(): - """ Validate we're running the right Python version. """ - major, minor = sys.version_info[:2] - - if major < 3 or (major == 3 and minor < 4): - print("Home Assistant requires atleast Python 3.4") - sys.exit(1) - - -def ensure_pip(): - """ Validate pip is installed so we can install packages on demand. """ - if importlib.find_loader('pip') is None: - print("Your Python installation did not bundle 'pip'") - print("Home Assistant requires 'pip' to be installed.") - print("Please install pip: " - "https://pip.pypa.io/en/latest/installing.html") - sys.exit(1) - - def ensure_config_path(config_dir): """ Gets the path to the configuration file. Creates one if it not exists. """ @@ -59,6 +39,8 @@ def ensure_config_path(config_dir): 'directory {} ').format(lib_dir)) sys.exit(1) + +def ensure_config_file(config_dir): config_path = config_util.ensure_config_exists(config_dir) if config_path is None: @@ -70,7 +52,8 @@ def ensure_config_path(config_dir): def get_arguments(): """ Get parsed passed in arguments. """ - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser( + description="Home Assistant: Observe, Control, Automate.") parser.add_argument( '-c', '--config', metavar='path_to_config_dir', @@ -90,12 +73,10 @@ def get_arguments(): def main(): """ Starts Home Assistant. """ - validate_python() - args = get_arguments() config_dir = os.path.join(os.getcwd(), args.config) - config_path = ensure_config_path(config_dir) + ensure_config_path(config_dir) if args.demo_mode: hass = bootstrap.from_config_dict({ @@ -103,7 +84,8 @@ def main(): 'demo': {} }, config_dir=config_dir) else: - hass = bootstrap.from_config_file(config_path) + config_file = ensure_config_file(config_dir) + hass = bootstrap.from_config_file(config_file) if args.open_ui: def open_browser(event): diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index e9f04d9ab71..03cb762d56e 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -151,7 +151,7 @@ def mount_local_lib_path(config_dir): # pylint: disable=too-many-branches, too-many-statements -def from_config_dict(config, hass=None, config_dir=None): +def from_config_dict(config, hass=None, config_dir=None, enable_log=True): """ Tries to configure Home Assistant from a config dict. @@ -166,7 +166,8 @@ def from_config_dict(config, hass=None, config_dir=None): process_ha_core_config(hass, config.get(core.DOMAIN, {})) - enable_logging(hass) + if enable_log: + enable_logging(hass) _ensure_loader_prepared(hass) @@ -209,9 +210,11 @@ def from_config_file(config_path, hass=None): hass.config.config_dir = config_dir mount_local_lib_path(config_dir) + enable_logging(hass) + config_dict = config_util.load_config_file(config_path) - return from_config_dict(config_dict, hass) + return from_config_dict(config_dict, hass, enable_log=False) def enable_logging(hass): diff --git a/homeassistant/config.py b/homeassistant/config.py index ca2d43eeb40..78da7f2a0d1 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -54,7 +54,8 @@ def ensure_config_exists(config_dir, detect_location=True): config_path = find_config_file(config_dir) if config_path is None: - _LOGGER.info("Unable to find configuration. Creating default one") + print("Unable to find configuration. Creating default one at", + config_dir) config_path = create_default_config(config_dir, detect_location) return config_path @@ -100,9 +101,7 @@ def create_default_config(config_dir, detect_location=True): return config_path except IOError: - _LOGGER.exception( - 'Unable to write default configuration file %s', config_path) - + print('Unable to create default configuration file', config_path) return None