From 285822b951c03399f3d89913efe02aacb7e8136d Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 27 Mar 2017 13:49:35 +0200 Subject: [PATCH] Update hassio --- .travis.yml | 17 ++++++++++ hassio_api/.pylint.d/hassio1.stats | Bin 0 -> 1504 bytes hassio_api/hassio/__main__.py | 13 ++++---- hassio_api/hassio/bootstrap.py | 3 +- hassio_api/hassio/config.py | 10 +++--- hassio_api/hassio/docker/__init__.py | 4 +-- hassio_api/hassio/docker/homeassistant.py | 10 +++--- hassio_api/hassio/tools.py | 5 +-- hassio_api/pylintrc | 38 ++++++++++++++++++++++ hassio_api/setup.py | 2 +- hassio_api/tox.ini | 16 +++++++++ 11 files changed, 92 insertions(+), 26 deletions(-) create mode 100644 .travis.yml create mode 100644 hassio_api/.pylint.d/hassio1.stats create mode 100644 hassio_api/pylintrc create mode 100644 hassio_api/tox.ini diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..41ab64c25 --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/hassio_api/.pylint.d/hassio1.stats b/hassio_api/.pylint.d/hassio1.stats new file mode 100644 index 0000000000000000000000000000000000000000..128e712e75c16f4fc91e14ac5bfbe7cf80eae6ad GIT binary patch literal 1504 zcmah}S##4c5KicohTbQ%Kts7gq2Vm|eS&NK#^#1|x_E*Ak8belvljHy#S2#MN;4n`2DBH&4}jr5wf zVwIg)3>BJ&(oX^kqnNJc=Etg4F=|^xkpK?nU~|U}<2H_zpE%uO^sH-V?6Ggy0;^V!z6tRK@R6K}LE?N>6F{RhZuK9-$_}{in z(qY6#kl{Cp1Q%^sLdH?u2c61{T~6UhW){OMaoNBJ!PZApI96vk25bpGG?-z3rajT+ zu_B7#(yiQ3O#ITyei9R*jsXetV-iDJY zoa$4wuvdgL{fkBo7w42K*M-w5oas}oXD@3B^%Tzb$)4IiJ7*gF}Yh)L0 z+HlKkoF@Yr1+opdHF$^B5WH){J+oSw4{%>Y4+;`;s^p9+KypO^sy6~ytd}hP* z-i(~!h0b`%Hn8g}8!WRfgiEH>7QEKj8zc9v4ev}fiFbtODjrh&eZYI2@qw*kwQa*k z^aIbIOvPs#zVvnGtIl^!{x=)GC(Z=UK9v1))jsZ=I8ShqlM&bpEq$C8~*@_ CnYs=D literal 0 HcmV?d00001 diff --git a/hassio_api/hassio/__main__.py b/hassio_api/hassio/__main__.py index 071664383..e79719f18 100644 --- a/hassio_api/hassio/__main__.py +++ b/hassio_api/hassio/__main__.py @@ -3,13 +3,12 @@ import asyncio import logging import aiohttp -from aiohttp import web import docker -import .bootstrap -import .tools -from .docker.homeassistant import DockerHomeAssistant -from .const import CONF_HOMEASSISTANT_TAG +import hassio.bootstrap as bootstrap +import hassio.tools as tools +from hassio.const import CONF_HOMEASSISTANT_TAG +from hassio.docker.homeassistant import DockerHomeAssistant _LOGGER = logging.getLogger(__name__) @@ -40,9 +39,9 @@ async def main(loop): while True: current = await tools.fetch_current_versions(websession) 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 - _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) config.homeassistant_tag = current[CONF_HOMEASSISTANT_TAG] diff --git a/hassio_api/hassio/bootstrap.py b/hassio_api/hassio/bootstrap.py index ddeef1186..a4c06cb55 100644 --- a/hassio_api/hassio/bootstrap.py +++ b/hassio_api/hassio/bootstrap.py @@ -1,5 +1,4 @@ """Bootstrap HassIO.""" -import asyncio import json import logging import os @@ -7,7 +6,7 @@ import os from colorlog import ColoredFormatter from .const import FILE_HASSIO_ADDONS -from .version import CoreConfig +from .config import CoreConfig _LOGGER = logging.getLogger(__name__) diff --git a/hassio_api/hassio/config.py b/hassio_api/hassio/config.py index 4d9b0e8e5..c78974735 100644 --- a/hassio_api/hassio/config.py +++ b/hassio_api/hassio/config.py @@ -11,7 +11,7 @@ from .const import ( _LOGGER = logging.getLogger(__name__) -class CoreConfig(Object): +class CoreConfig(object): """Hold all config data.""" def __init__(self, config_file=FILE_HASSIO_CONFIG): @@ -22,10 +22,10 @@ class CoreConfig(Object): # init or load data if os.path.isfile(self._filename): try: - with open(self._filename 'r') as cfile: + with open(self._filename, 'r') as cfile: self._data = json.loads(cfile.read()) except OSError: - _LOGGER.waring("Can't read %s", self._filename) + _LOGGER.warning("Can't read %s", self._filename) if not self._data: self._data.update({ @@ -35,7 +35,7 @@ class CoreConfig(Object): }) # update version - versions.update({ + self._data.update({ CONF_SUPERVISOR_IMAGE: os.environ['SUPERVISOR_IMAGE'], CONF_SUPERVISOR_TAG: os.environ['SUPERVISOR_TAG'], }) @@ -64,7 +64,7 @@ class CoreConfig(Object): def homeassistant_tag(self, value): """Set docker homeassistant tag.""" self._data[CONF_HOMEASSISTANT_TAG] = value - self.store() + self.save() @property def supervisor_image(self): diff --git a/hassio_api/hassio/docker/__init__.py b/hassio_api/hassio/docker/__init__.py index a4da8fd32..f95d6e3a9 100644 --- a/hassio_api/hassio/docker/__init__.py +++ b/hassio_api/hassio/docker/__init__.py @@ -41,7 +41,7 @@ class DockerBase(object): if tag != "latest": image = self.dock.images.get("{}:{}".format(self.image, tag)) 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) return False return True @@ -70,7 +70,7 @@ class DockerBase(object): 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): """Run docker image. diff --git a/hassio_api/hassio/docker/homeassistant.py b/hassio_api/hassio/docker/homeassistant.py index c810c01c4..f9f36e7f0 100644 --- a/hassio_api/hassio/docker/homeassistant.py +++ b/hassio_api/hassio/docker/homeassistant.py @@ -1,10 +1,10 @@ """Init file for HassIO docker object.""" -import asyncio +import logging import docker -import . from DockerBase -from ..const.py import HASSIO_DOCKER +from . import DockerBase +from ..const import HASSIO_DOCKER _LOGGER = logging.getLogger(__name__) HASS_DOCKER_NAME = 'homeassistant' @@ -29,7 +29,7 @@ class DockerHomeAssistant(DockerBase): try: self.container = self.dock.containers.run( self.image, - name=self.docker_nme, + name=self.docker_name, remove=True, network_mode='host', restart_policy={ @@ -43,7 +43,7 @@ class DockerHomeAssistant(DockerBase): self.config.path_ssl_docker: {'bind': '/ssl', 'mode': 'rw'}, }) - except docker.errors.DockerException as err: + except docker.errors.DockerException: _LOGGER.error("Can't run %s", self.image) return False diff --git a/hassio_api/hassio/tools.py b/hassio_api/hassio/tools.py index 83e7113e4..26bebde3b 100644 --- a/hassio_api/hassio/tools.py +++ b/hassio_api/hassio/tools.py @@ -1,8 +1,6 @@ """Tools file for HassIO.""" -import asyncio import logging -import aiohttp import async_timeout from .const import URL_SUPERVISOR_VERSION @@ -15,8 +13,7 @@ async def fetch_current_versions(websession): try: with async_timeout.timeout(10, loop=websession.loop): 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 _LOGGER.warning("Can't fetch versions from github! %s", err) - return None diff --git a/hassio_api/pylintrc b/hassio_api/pylintrc new file mode 100644 index 000000000..4c0b15230 --- /dev/null +++ b/hassio_api/pylintrc @@ -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 diff --git a/hassio_api/setup.py b/hassio_api/setup.py index 966de5a56..f0406904b 100644 --- a/hassio_api/setup.py +++ b/hassio_api/setup.py @@ -34,6 +34,6 @@ setup( 'async_timeout', 'aiohttp', 'docker-py', - 'colorlog' + 'colorlog', ] ) diff --git a/hassio_api/tox.ini b/hassio_api/tox.ini new file mode 100644 index 000000000..89d5eb7bb --- /dev/null +++ b/hassio_api/tox.ini @@ -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