Skip to content

Commit

Permalink
Fix version conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
pvizeli committed Aug 14, 2017
2 parents d08343d + 5999b48 commit 6cab017
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
38 changes: 21 additions & 17 deletions hassio/addons/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def __init__(self, config, loop, dock, data, slug):
self.data = data
self._id = slug

self.addon_docker = DockerAddon(config, loop, dock, self)
self.docker = DockerAddon(config, loop, dock, self)

async def load(self):
"""Async initialize of object."""
if self.is_installed:
await self.addon_docker.attach()
await self.docker.attach()

@property
def slug(self):
Expand Down Expand Up @@ -434,7 +434,7 @@ async def install(self, version=None):
self.path_data.mkdir()

version = version or self.last_version
if not await self.addon_docker.install(version):
if not await self.docker.install(version):
return False

self._set_install(version)
Expand All @@ -443,7 +443,7 @@ async def install(self, version=None):
@check_installed
async def uninstall(self):
"""Remove a addon."""
if not await self.addon_docker.remove():
if not await self.docker.remove():
return False

if self.path_data.is_dir():
Expand All @@ -459,7 +459,7 @@ async def state(self):
if not self.is_installed:
return STATE_NONE

if await self.addon_docker.is_running():
if await self.docker.is_running():
return STATE_STARTED
return STATE_STOPPED

Expand All @@ -469,30 +469,34 @@ def start(self):
Return a coroutine.
"""
return self.addon_docker.run()
return self.docker.run()

@check_installed
def stop(self):
"""Stop addon.
Return a coroutine.
"""
return self.addon_docker.stop()
return self.docker.stop()

@check_installed
async def update(self, version=None):
"""Update addon."""
version = version or self.last_version
last_state = await self.state()

if version == self.version_installed:
_LOGGER.warning(
"Addon %s is already installed in %s", self._id, version)
return False

if not await self.addon_docker.update(version):
if not await self.docker.update(version):
return False

self._set_update(version)

# restore state
if last_state == STATE_STARTED:
return await self.docker.run()
return True

@check_installed
Expand All @@ -501,23 +505,23 @@ def restart(self):
Return a coroutine.
"""
return self.addon_docker.restart()
return self.docker.restart()

@check_installed
def logs(self):
"""Return addons log output.
Return a coroutine.
"""
return self.addon_docker.logs()
return self.docker.logs()

@check_installed
async def snapshot(self, tar_file):
"""Snapshot a state of a addon."""
with TemporaryDirectory(dir=str(self.config.path_tmp)) as temp:
# store local image
if self.need_build and not await \
self.addon_docker.export_image(Path(temp, "image.tar")):
self.docker.export_image(Path(temp, "image.tar")):
return False

data = {
Expand Down Expand Up @@ -582,15 +586,15 @@ def _extract_tar():

# check version / restore image
version = data[ATTR_VERSION]
if version != self.addon_docker.version:
if version != self.docker.version:
image_file = Path(temp, "image.tar")
if image_file.is_file():
await self.addon_docker.import_image(image_file, version)
await self.docker.import_image(image_file, version)
else:
if await self.addon_docker.install(version):
await self.addon_docker.cleanup()
if await self.docker.install(version):
await self.docker.cleanup()
else:
await self.addon_docker.stop()
await self.docker.stop()

# restore data
def _restore_data():
Expand Down
3 changes: 2 additions & 1 deletion hassio/addons/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ async def clone(self):
try:
_LOGGER.info("Clone addon %s repository", self.url)
self.repo = await self.loop.run_in_executor(
None, git.Repo.clone_from, self.url, str(self.path))
None, git.Repo.clone_from, self.url, str(self.path),
recursive=True)

except (git.InvalidGitRepositoryError, git.NoSuchPathError,
git.GitCommandError) as err:
Expand Down
2 changes: 1 addition & 1 deletion hassio/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Const file for HassIO."""
from pathlib import Path

HASSIO_VERSION = '0.52'
HASSIO_VERSION = '0.53'

URL_HASSIO_VERSION = ('https://raw.githubusercontent.com/home-assistant/'
'hassio/{}/version.json')
Expand Down
9 changes: 2 additions & 7 deletions hassio/dock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,15 @@ def _update(self, tag):
Need run inside executor.
"""
was_running = self._is_running()

_LOGGER.info(
"Update docker %s with %s:%s", self.version, self.image, tag)

# update docker image
if not self._install(tag):
return False

# run or cleanup container
if was_running:
self._run()
else:
self._stop()
# container
self._stop()

# cleanup images
self._cleanup()
Expand Down
5 changes: 4 additions & 1 deletion hassio/homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ async def update(self, version=None):
_LOGGER.warning("Version %s is already installed", version)
return False

return await self.docker.update(version)
try:
return await self.docker.update(version)
finally:
await self.docker.run()

def run(self):
"""Run HomeAssistant docker.
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hassio": "0.52",
"hassio": "0.53",
"homeassistant": "0.51.2",
"resinos": "1.0",
"resinhup": "0.3",
Expand Down

0 comments on commit 6cab017

Please sign in to comment.