mirror of
https://github.com/home-assistant/core
synced 2024-08-02 23:40:32 +02:00
Cleaned up main file to remove dependency management.
This commit is contained in:
parent
3839c3d0ef
commit
18e32165a4
@ -4,12 +4,14 @@ from __future__ import print_function
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
DEPENDENCIES = ['requests>=2.0', 'pyyaml>=3.11', 'pytz>=2015.2']
|
from homeassistant import bootstrap
|
||||||
IS_VIRTUAL = (getattr(sys, 'base_prefix', sys.prefix) != sys.prefix or
|
import homeassistant.config as config_util
|
||||||
hasattr(sys, 'real_prefix'))
|
from homeassistant.components import frontend, demo
|
||||||
|
|
||||||
|
USER_DATA_DIR = os.getenv('APPDATA') if os.name == "nt" \
|
||||||
|
else os.path.expanduser('~')
|
||||||
|
|
||||||
|
|
||||||
def validate_python():
|
def validate_python():
|
||||||
@ -31,54 +33,6 @@ def ensure_pip():
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
# Copy of homeassistant.util.package because we can't import yet
|
|
||||||
def install_package(package):
|
|
||||||
"""Install a package on PyPi. Accepts pip compatible package strings.
|
|
||||||
Return boolean if install successfull."""
|
|
||||||
args = [sys.executable, '-m', 'pip', 'install', '--quiet', package]
|
|
||||||
if not IS_VIRTUAL:
|
|
||||||
args.append('--user')
|
|
||||||
try:
|
|
||||||
return 0 == subprocess.call(args)
|
|
||||||
except subprocess.SubprocessError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def validate_dependencies():
|
|
||||||
""" Validate all dependencies that HA uses. """
|
|
||||||
ensure_pip()
|
|
||||||
|
|
||||||
print("Validating dependencies...")
|
|
||||||
import_fail = False
|
|
||||||
|
|
||||||
for requirement in DEPENDENCIES:
|
|
||||||
if not install_package(requirement):
|
|
||||||
import_fail = True
|
|
||||||
print('Fatal Error: Unable to install dependency', requirement)
|
|
||||||
|
|
||||||
if import_fail:
|
|
||||||
print(("Install dependencies by running: "
|
|
||||||
"python3 -m pip install -r requirements.txt"))
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_path_and_load_bootstrap():
|
|
||||||
""" Ensure sys load path is correct and load Home Assistant bootstrap. """
|
|
||||||
try:
|
|
||||||
from homeassistant import bootstrap
|
|
||||||
|
|
||||||
except ImportError:
|
|
||||||
# This is to add support to load Home Assistant using
|
|
||||||
# `python3 homeassistant` instead of `python3 -m homeassistant`
|
|
||||||
|
|
||||||
# Insert the parent directory of this file into the module search path
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
||||||
|
|
||||||
from homeassistant import bootstrap
|
|
||||||
|
|
||||||
return bootstrap
|
|
||||||
|
|
||||||
|
|
||||||
def validate_git_submodules():
|
def validate_git_submodules():
|
||||||
""" Validate the git submodules are cloned. """
|
""" Validate the git submodules are cloned. """
|
||||||
try:
|
try:
|
||||||
@ -94,13 +48,25 @@ def ensure_config_path(config_dir):
|
|||||||
""" Gets the path to the configuration file.
|
""" Gets the path to the configuration file.
|
||||||
Creates one if it not exists. """
|
Creates one if it not exists. """
|
||||||
|
|
||||||
|
lib_dir = os.path.join(config_dir, 'lib')
|
||||||
|
|
||||||
# Test if configuration directory exists
|
# Test if configuration directory exists
|
||||||
if not os.path.isdir(config_dir):
|
if not os.path.isdir(config_dir):
|
||||||
print(('Fatal Error: Unable to find specified configuration '
|
try:
|
||||||
|
os.mkdir(config_dir)
|
||||||
|
except OSError:
|
||||||
|
print(('Fatal Error: Unable to create specified configuration '
|
||||||
'directory {} ').format(config_dir))
|
'directory {} ').format(config_dir))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
import homeassistant.config as config_util
|
# Test if library directory exists
|
||||||
|
if not os.path.isdir(lib_dir):
|
||||||
|
try:
|
||||||
|
os.mkdir(lib_dir)
|
||||||
|
except OSError:
|
||||||
|
print(('Fatal Error: Unable to create library '
|
||||||
|
'directory {} ').format(lib_dir))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
config_path = config_util.ensure_config_exists(config_dir)
|
config_path = config_util.ensure_config_exists(config_dir)
|
||||||
|
|
||||||
@ -117,7 +83,7 @@ def get_arguments():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--config',
|
'-c', '--config',
|
||||||
metavar='path_to_config_dir',
|
metavar='path_to_config_dir',
|
||||||
default="config",
|
default=os.path.join(USER_DATA_DIR, '.homeassistant'),
|
||||||
help="Directory that contains the Home Assistant configuration")
|
help="Directory that contains the Home Assistant configuration")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--demo-mode',
|
'--demo-mode',
|
||||||
@ -134,12 +100,6 @@ def get_arguments():
|
|||||||
def main():
|
def main():
|
||||||
""" Starts Home Assistant. """
|
""" Starts Home Assistant. """
|
||||||
validate_python()
|
validate_python()
|
||||||
validate_dependencies()
|
|
||||||
|
|
||||||
# Windows needs this to pick up new modules
|
|
||||||
importlib.invalidate_caches()
|
|
||||||
|
|
||||||
bootstrap = ensure_path_and_load_bootstrap()
|
|
||||||
|
|
||||||
validate_git_submodules()
|
validate_git_submodules()
|
||||||
|
|
||||||
@ -149,8 +109,6 @@ def main():
|
|||||||
config_path = ensure_config_path(config_dir)
|
config_path = ensure_config_path(config_dir)
|
||||||
|
|
||||||
if args.demo_mode:
|
if args.demo_mode:
|
||||||
from homeassistant.components import frontend, demo
|
|
||||||
|
|
||||||
hass = bootstrap.from_config_dict({
|
hass = bootstrap.from_config_dict({
|
||||||
frontend.DOMAIN: {},
|
frontend.DOMAIN: {},
|
||||||
demo.DOMAIN: {}
|
demo.DOMAIN: {}
|
||||||
@ -159,11 +117,10 @@ def main():
|
|||||||
hass = bootstrap.from_config_file(config_path)
|
hass = bootstrap.from_config_file(config_path)
|
||||||
|
|
||||||
if args.open_ui:
|
if args.open_ui:
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
|
||||||
|
|
||||||
def open_browser(event):
|
def open_browser(event):
|
||||||
""" Open the webinterface in a browser. """
|
""" Open the webinterface in a browser. """
|
||||||
if hass.config.api is not None:
|
if hass.config.api is not None:
|
||||||
|
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||||
import webbrowser
|
import webbrowser
|
||||||
webbrowser.open(hass.config.api.base_url)
|
webbrowser.open(hass.config.api.base_url)
|
||||||
|
|
||||||
|
3
setup.py
3
setup.py
@ -30,8 +30,7 @@ setup(
|
|||||||
package_data=PACKAGE_DATA,
|
package_data=PACKAGE_DATA,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
platforms='any',
|
platforms='any',
|
||||||
install_requires=['requests==2.7.0', 'pyyaml==3.11', 'pytz==2015.4',
|
install_requires=['requests==2.7.0', 'pyyaml==3.11', 'pytz==2015.4'],
|
||||||
'netdisco==0.3', 'astral==0.8.1'],
|
|
||||||
keywords=['home', 'automation'],
|
keywords=['home', 'automation'],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
Loading…
Reference in New Issue
Block a user