Update hassio

This commit is contained in:
Pascal Vizeli 2017-03-27 13:49:35 +02:00
parent 13a00f5963
commit 285822b951
11 changed files with 92 additions and 26 deletions

17
.travis.yml Normal file
View File

@ -0,0 +1,17 @@
sudo: false
matrix:
fast_finish: true
include:
- python: "3.5"
env: TOXENV=py35
- python: "3.6"
env: TOXENV=py36
- python: "3.6-dev"
env: TOXENV=py36
cache:
directories:
- $HOME/.cache/pip
install: pip install -U tox
language: python
script: tox hassio_api

Binary file not shown.

View File

@ -3,13 +3,12 @@ import asyncio
import logging import logging
import aiohttp import aiohttp
from aiohttp import web
import docker import docker
import .bootstrap import hassio.bootstrap as bootstrap
import .tools import hassio.tools as tools
from .docker.homeassistant import DockerHomeAssistant from hassio.const import CONF_HOMEASSISTANT_TAG
from .const import CONF_HOMEASSISTANT_TAG from hassio.docker.homeassistant import DockerHomeAssistant
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -40,9 +39,9 @@ async def main(loop):
while True: while True:
current = await tools.fetch_current_versions(websession) current = await tools.fetch_current_versions(websession)
if current and CONF_HOMEASSISTANT_TAG in current: if current and CONF_HOMEASSISTANT_TAG in current:
if await docker_hass.install(current[CONF_SUPERVISOR_TAG]): if await docker_hass.install(current[CONF_HOMEASSISTANT_TAG]):
break break
_LOGGER.waring("Can't fetch info from github. Retry in 60") _LOGGER.warning("Can't fetch info from github. Retry in 60")
await asyncio.sleep(60, loop=loop) await asyncio.sleep(60, loop=loop)
config.homeassistant_tag = current[CONF_HOMEASSISTANT_TAG] config.homeassistant_tag = current[CONF_HOMEASSISTANT_TAG]

View File

@ -1,5 +1,4 @@
"""Bootstrap HassIO.""" """Bootstrap HassIO."""
import asyncio
import json import json
import logging import logging
import os import os
@ -7,7 +6,7 @@ import os
from colorlog import ColoredFormatter from colorlog import ColoredFormatter
from .const import FILE_HASSIO_ADDONS from .const import FILE_HASSIO_ADDONS
from .version import CoreConfig from .config import CoreConfig
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -11,7 +11,7 @@ from .const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
class CoreConfig(Object): class CoreConfig(object):
"""Hold all config data.""" """Hold all config data."""
def __init__(self, config_file=FILE_HASSIO_CONFIG): def __init__(self, config_file=FILE_HASSIO_CONFIG):
@ -22,10 +22,10 @@ class CoreConfig(Object):
# init or load data # init or load data
if os.path.isfile(self._filename): if os.path.isfile(self._filename):
try: try:
with open(self._filename 'r') as cfile: with open(self._filename, 'r') as cfile:
self._data = json.loads(cfile.read()) self._data = json.loads(cfile.read())
except OSError: except OSError:
_LOGGER.waring("Can't read %s", self._filename) _LOGGER.warning("Can't read %s", self._filename)
if not self._data: if not self._data:
self._data.update({ self._data.update({
@ -35,7 +35,7 @@ class CoreConfig(Object):
}) })
# update version # update version
versions.update({ self._data.update({
CONF_SUPERVISOR_IMAGE: os.environ['SUPERVISOR_IMAGE'], CONF_SUPERVISOR_IMAGE: os.environ['SUPERVISOR_IMAGE'],
CONF_SUPERVISOR_TAG: os.environ['SUPERVISOR_TAG'], CONF_SUPERVISOR_TAG: os.environ['SUPERVISOR_TAG'],
}) })
@ -64,7 +64,7 @@ class CoreConfig(Object):
def homeassistant_tag(self, value): def homeassistant_tag(self, value):
"""Set docker homeassistant tag.""" """Set docker homeassistant tag."""
self._data[CONF_HOMEASSISTANT_TAG] = value self._data[CONF_HOMEASSISTANT_TAG] = value
self.store() self.save()
@property @property
def supervisor_image(self): def supervisor_image(self):

View File

@ -41,7 +41,7 @@ class DockerBase(object):
if tag != "latest": if tag != "latest":
image = self.dock.images.get("{}:{}".format(self.image, tag)) image = self.dock.images.get("{}:{}".format(self.image, tag))
image.tag(self.image, tag='latest') image.tag(self.image, tag='latest')
except docker.errors.APIError as err: except docker.errors.APIError:
_LOGGER.error("Can't pull %s:%s", self.image, tag) _LOGGER.error("Can't pull %s:%s", self.image, tag)
return False return False
return True return True
@ -70,7 +70,7 @@ class DockerBase(object):
Return a Future. Return a Future.
""" """
return self.loop.run_in_executor(None, self._run, tag) return self.loop.run_in_executor(None, self._run)
def _run(self): def _run(self):
"""Run docker image. """Run docker image.

View File

@ -1,10 +1,10 @@
"""Init file for HassIO docker object.""" """Init file for HassIO docker object."""
import asyncio import logging
import docker import docker
import . from DockerBase from . import DockerBase
from ..const.py import HASSIO_DOCKER from ..const import HASSIO_DOCKER
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
HASS_DOCKER_NAME = 'homeassistant' HASS_DOCKER_NAME = 'homeassistant'
@ -29,7 +29,7 @@ class DockerHomeAssistant(DockerBase):
try: try:
self.container = self.dock.containers.run( self.container = self.dock.containers.run(
self.image, self.image,
name=self.docker_nme, name=self.docker_name,
remove=True, remove=True,
network_mode='host', network_mode='host',
restart_policy={ restart_policy={
@ -43,7 +43,7 @@ class DockerHomeAssistant(DockerBase):
self.config.path_ssl_docker: self.config.path_ssl_docker:
{'bind': '/ssl', 'mode': 'rw'}, {'bind': '/ssl', 'mode': 'rw'},
}) })
except docker.errors.DockerException as err: except docker.errors.DockerException:
_LOGGER.error("Can't run %s", self.image) _LOGGER.error("Can't run %s", self.image)
return False return False

View File

@ -1,8 +1,6 @@
"""Tools file for HassIO.""" """Tools file for HassIO."""
import asyncio
import logging import logging
import aiohttp
import async_timeout import async_timeout
from .const import URL_SUPERVISOR_VERSION from .const import URL_SUPERVISOR_VERSION
@ -15,8 +13,7 @@ async def fetch_current_versions(websession):
try: try:
with async_timeout.timeout(10, loop=websession.loop): with async_timeout.timeout(10, loop=websession.loop):
async with websession.get(URL_SUPERVISOR_VERSION) as request: async with websession.get(URL_SUPERVISOR_VERSION) as request:
return (await request.json()) return await request.json()
except Exception as err: # pylint: disable=broad-except except Exception as err: # pylint: disable=broad-except
_LOGGER.warning("Can't fetch versions from github! %s", err) _LOGGER.warning("Can't fetch versions from github! %s", err)
return None

38
hassio_api/pylintrc Normal file
View File

@ -0,0 +1,38 @@
[MASTER]
reports=no
# Reasons disabled:
# locally-disabled - it spams too much
# duplicate-code - unavoidable
# cyclic-import - doesn't test if both import on load
# abstract-class-little-used - prevents from setting right foundation
# abstract-class-not-used - is flaky, should not show up but does
# unused-argument - generic callbacks and setup methods create a lot of warnings
# global-statement - used for the on-demand requirement installation
# redefined-variable-type - this is Python, we're duck typing!
# too-many-* - are not enforced for the sake of readability
# too-few-* - same as too-many-*
# abstract-method - with intro of async there are always methods missing
disable=
locally-disabled,
duplicate-code,
cyclic-import,
abstract-class-little-used,
abstract-class-not-used,
unused-argument,
global-statement,
redefined-variable-type,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-locals,
too-many-public-methods,
too-many-return-statements,
too-many-statements,
too-many-lines,
too-few-public-methods,
abstract-method
[EXCEPTIONS]
overgeneral-exceptions=Exception,HomeAssistantError

View File

@ -34,6 +34,6 @@ setup(
'async_timeout', 'async_timeout',
'aiohttp', 'aiohttp',
'docker-py', 'docker-py',
'colorlog' 'colorlog',
] ]
) )

16
hassio_api/tox.ini Normal file
View File

@ -0,0 +1,16 @@
[tox]
envlist = lint
[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/hassio
deps =
flake8
pylint
[testenv:lint]
basepython = python3
ignore_errors = True
commands =
flake8 hassio
pylint hassio