Skip to content

Commit

Permalink
Fixes loading issues on python < 3.7...
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jun 2, 2019
1 parent 3ca1e57 commit 5f21c71
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 68 deletions.
15 changes: 8 additions & 7 deletions custom_components/hacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from homeassistant.helpers.aiohttp_client import async_create_clientsession
import homeassistant.helpers.config_validation as cv

from custom_components.hacs.hacsbase import HacsBase as hacs
from custom_components.hacs.const import (
from .hacsbase import HacsBase as hacs
from .const import (
CUSTOM_UPDATER_LOCATIONS,
STARTUP,
ISSUE_URL,
Expand All @@ -29,9 +29,10 @@
ELEMENT_TYPES,
VERSION,
IFRAME,
BLACKLIST,
)

from custom_components.hacs.frontend.views import (
from .frontend.views import (
HacsStaticView,
HacsErrorView,
HacsPluginView,
Expand Down Expand Up @@ -115,9 +116,9 @@ async def async_setup(hass, config): # pylint: disable=unused-argument

async def configure_hacs(hass, github_token, hass_config_dir):
"""Configure HACS."""
from custom_components.hacs.aiogithub import AIOGitHub
from custom_components.hacs.hacsmigration import HacsMigration
from custom_components.hacs.hacsstorage import HacsStorage
from .aiogithub import AIOGitHub
from .hacsmigration import HacsMigration
from .hacsstorage import HacsStorage

hacs.migration = HacsMigration()
hacs.storage = HacsStorage()
Expand All @@ -126,4 +127,4 @@ async def configure_hacs(hass, github_token, hass_config_dir):

hacs.hass = hass
hacs.config_dir = hass_config_dir
hacs.blacklist = hacs.const.BLACKLIST
hacs.blacklist = BLACKLIST
8 changes: 4 additions & 4 deletions custom_components/hacs/blueprints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Initialize blueprints."""
# pylint: disable=unused-import
from custom_components.hacs.hacsrepositorybase import HacsRepositoryBase
from custom_components.hacs.hacsrepositoryintegration import HacsRepositoryIntegration
from custom_components.hacs.hacsrepositorybaseplugin import HacsRepositoryPlugin
from custom_components.hacs.hacsviewbase import HacsViewBase
from .hacsrepositorybase import HacsRepositoryBase
from .hacsrepositoryintegration import HacsRepositoryIntegration
from .hacsrepositorybaseplugin import HacsRepositoryPlugin
from .hacsviewbase import HacsViewBase
2 changes: 1 addition & 1 deletion custom_components/hacs/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Constants for HACS"""
VERSION = "0.4.2"
VERSION = "0.4.3"
NAME_LONG = "HACS (Home Assistant Community Store)"
NAME_SHORT = "HACS"
STORAGE_VERSION = "1"
Expand Down
16 changes: 8 additions & 8 deletions custom_components/hacs/frontend/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Initialize frontend views."""
from custom_components.hacs.frontend.views.error import HacsErrorView
from custom_components.hacs.frontend.views.static import HacsStaticView
from custom_components.hacs.frontend.views.plugin import HacsPluginView
from custom_components.hacs.frontend.views.overview import HacsOverviewView
from custom_components.hacs.frontend.views.store import HacsStoreView
from custom_components.hacs.frontend.views.settings import HacsSettingsView
from custom_components.hacs.frontend.views.repository import HacsRepositoryView
from custom_components.hacs.frontend.views.api import HacsAPIView
from .error import HacsErrorView
from .static import HacsStaticView
from .plugin import HacsPluginView
from .overview import HacsOverviewView
from .store import HacsStoreView
from .settings import HacsSettingsView
from .repository import HacsRepositoryView
from .api import HacsAPIView
4 changes: 2 additions & 2 deletions custom_components/hacs/frontend/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint: disable=broad-except
import logging
from aiohttp import web
from custom_components.hacs.blueprints import HacsViewBase
from ...blueprints import HacsViewBase

_LOGGER = logging.getLogger('custom_components.hacs.frontend')

Expand Down Expand Up @@ -81,7 +81,7 @@ async def get(self, request, element, action=None): # pylint: disable=unused-ar
return self.json(jsons)

elif element == "log" and action == "get":
from custom_components.hacs.handler.log import get_log_file_content
from ...handler.log import get_log_file_content
content = self.base_content
content += await get_log_file_content(self.config_dir)
return web.Response(body=content, content_type="text/html", charset="utf-8")
Expand Down
6 changes: 3 additions & 3 deletions custom_components/hacs/frontend/views/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

from aiohttp import web

from custom_components.hacs.blueprints import HacsViewBase
from custom_components.hacs.const import ERROR, ISSUE_URL
from ...blueprints import HacsViewBase
from ...const import ERROR, ISSUE_URL

_LOGGER = logging.getLogger('custom_components.hacs.frontend')
_LOGGER = logging.getLogger('custom_components.hacs..frontend')

class HacsErrorView(HacsViewBase):
"""Serve error."""
Expand Down
7 changes: 4 additions & 3 deletions custom_components/hacs/frontend/views/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# pylint: disable=broad-except
import logging
from aiohttp import web
from custom_components.hacs.blueprints import HacsViewBase
from ...blueprints import HacsViewBase
from ...const import NO_ELEMENTS

_LOGGER = logging.getLogger('custom_components.hacs.frontend')

Expand All @@ -26,7 +27,7 @@ async def get(self, request): # pylint: disable=unused-argument

if not self.repositories:
if not self.data["task_running"]:
content += self.const.NO_ELEMENTS
content += NO_ELEMENTS

else:
for repository in self.repositories:
Expand Down Expand Up @@ -89,7 +90,7 @@ async def get(self, request): # pylint: disable=unused-argument

if not plugins and not integrations:
if not self.data["task_running"]:
content += self.const.NO_ELEMENTS
content += NO_ELEMENTS


except Exception as exception:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/frontend/views/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from aiohttp import web
from aiohttp.web_exceptions import HTTPNotFound
from custom_components.hacs.blueprints import HacsViewBase
from ...blueprints import HacsViewBase

_LOGGER = logging.getLogger('custom_components.hacs.frontend')

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/frontend/views/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint: disable=broad-except
import logging
from aiohttp import web
from custom_components.hacs.blueprints import HacsViewBase
from ...blueprints import HacsViewBase

_LOGGER = logging.getLogger('custom_components.hacs.frontend')

Expand Down
4 changes: 2 additions & 2 deletions custom_components/hacs/frontend/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from aiohttp import web
from homeassistant.const import __version__ as HAVERSION

from custom_components.hacs.blueprints import HacsViewBase
from custom_components.hacs.const import ISSUE_URL, NAME_LONG
from ...blueprints import HacsViewBase
from ...const import ISSUE_URL, NAME_LONG

_LOGGER = logging.getLogger('custom_components.hacs.frontend')

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/frontend/views/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from aiohttp import web
import aiofiles
from custom_components.hacs.blueprints import HacsViewBase
from ...blueprints import HacsViewBase

_LOGGER = logging.getLogger('custom_components.hacs.frontend')

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/frontend/views/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint: disable=broad-except
import logging
from aiohttp import web
from custom_components.hacs.blueprints import HacsViewBase
from ...blueprints import HacsViewBase

_LOGGER = logging.getLogger('custom_components.hacs.frontend')

Expand Down
17 changes: 8 additions & 9 deletions custom_components/hacs/hacsbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import logging
import uuid
from datetime import timedelta

from homeassistant.helpers.event import async_track_time_interval
from custom_components.hacs.aiogithub import AIOGitHubException
from .aiogithub import AIOGitHubException
from .const import DEFAULT_REPOSITORIES

_LOGGER = logging.getLogger('custom_components.hacs.hacs')


class HacsBase:
"""The base class of HACS, nested thoughout the project."""
import custom_components.hacs.const as const

const = None
migration = None
storage = None
hacs = None
Expand All @@ -31,7 +30,7 @@ class HacsBase:

async def startup_tasks(self):
"""Run startup_tasks."""
from custom_components.hacs.hacsrepositoryintegration import HacsRepositoryIntegration
from .hacsrepositoryintegration import HacsRepositoryIntegration
self.data["task_running"] = True

_LOGGER.info("Runing startup tasks.")
Expand Down Expand Up @@ -63,8 +62,8 @@ async def startup_tasks(self):

async def register_new_repository(self, element_type, repo, repositoryobject=None):
"""Register a new repository."""
from custom_components.hacs.exceptions import HacsBaseException, HacsRequirement
from custom_components.hacs.blueprints import HacsRepositoryIntegration, HacsRepositoryPlugin
from .exceptions import HacsBaseException, HacsRequirement
from .blueprints import HacsRepositoryIntegration, HacsRepositoryPlugin

_LOGGER.debug("Starting repository registration for %s", repo)

Expand Down Expand Up @@ -144,8 +143,8 @@ async def get_repositories(self):
repositories["plugin"] = await self.aiogithub.get_org_repos("custom-cards")

# Additional repositories (Not implemented)
for repository_type in self.const.DEFAULT_REPOSITORIES:
for repository in self.const.DEFAULT_REPOSITORIES[repository_type]:
for repository_type in DEFAULT_REPOSITORIES:
for repository in DEFAULT_REPOSITORIES[repository_type]:
result = await self.aiogithub.get_repo(repository)
repositories[repository_type].append(result)

Expand Down
5 changes: 3 additions & 2 deletions custom_components/hacs/hacsmigration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
from shutil import copy2

from custom_components.hacs.hacsbase import HacsBase
from .hacsbase import HacsBase
from .const import STORAGE_VERSION

_LOGGER = logging.getLogger('custom_components.hacs.migration')

Expand Down Expand Up @@ -34,7 +35,7 @@ async def validate(self):
# Run the rest.
await self.update_repositories()

elif self.old["hacs"].get("schema") == self.const.STORAGE_VERSION:
elif self.old["hacs"].get("schema") == STORAGE_VERSION:
pass

else:
Expand Down
17 changes: 9 additions & 8 deletions custom_components/hacs/hacsrepositorybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import os
import shutil

from custom_components.hacs.aiogithub import AIOGitHubException
from custom_components.hacs.hacsbase import HacsBase
from custom_components.hacs.exceptions import HacsRepositoryInfo, HacsUserScrewupException, HacsBaseException, HacsBlacklistException
from custom_components.hacs.handler.download import async_download_file, async_save_file
from .aiogithub import AIOGitHubException
from .hacsbase import HacsBase
from .exceptions import HacsRepositoryInfo, HacsUserScrewupException, HacsBaseException, HacsBlacklistException
from .handler.download import async_download_file, async_save_file
from .const import DEFAULT_REPOSITORIES, VERSION

_LOGGER = logging.getLogger('custom_components.hacs.repository')

Expand Down Expand Up @@ -54,9 +55,9 @@ def custom(self):
"""Return flag if the repository is custom."""
if self.repository_name.split("/")[0] in ["custom-components", "custom-cards"]:
return False
elif self.repository_name in self.const.DEFAULT_REPOSITORIES["integration"]:
elif self.repository_name in DEFAULT_REPOSITORIES["integration"]:
return False
elif self.repository_name in self.const.DEFAULT_REPOSITORIES["plugin"]:
elif self.repository_name in DEFAULT_REPOSITORIES["plugin"]:
return False
return True

Expand Down Expand Up @@ -110,7 +111,7 @@ async def setup_repository(self):
if self.repository_name == "custom-components/hacs":
self.hide = True
self.installed = True
self.version_installed = self.const.VERSION
self.version_installed = VERSION

# Validate the repository name
await self.validate_repository_name()
Expand Down Expand Up @@ -206,7 +207,7 @@ async def install(self):
self.installed = True
if self.repository_type == "integration":
self.pending_restart = True
_LOGGER.info(f'({self.repository_name}) - installation completed in {(datetime.now() - start_time).seconds} seconds')
_LOGGER.info('(%s) - installation completed in %s seconds', self.repository_name, (datetime.now() - start_time).seconds)


async def remove(self):
Expand Down
6 changes: 3 additions & 3 deletions custom_components/hacs/hacsrepositorybaseplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# pylint: disable=too-many-instance-attributes,invalid-name,broad-except
import logging

from custom_components.hacs.aiogithub import AIOGitHubException
from custom_components.hacs.blueprints import HacsRepositoryBase
from custom_components.hacs.exceptions import HacsRequirement
from .aiogithub import AIOGitHubException
from .blueprints import HacsRepositoryBase
from .exceptions import HacsRequirement

_LOGGER = logging.getLogger('custom_components.hacs.repository')

Expand Down
4 changes: 2 additions & 2 deletions custom_components/hacs/hacsrepositoryintegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import logging
import json

from custom_components.hacs.blueprints import HacsRepositoryBase
from custom_components.hacs.exceptions import HacsRequirement
from .blueprints import HacsRepositoryBase
from .exceptions import HacsRequirement

_LOGGER = logging.getLogger('custom_components.hacs.repository')

Expand Down
17 changes: 9 additions & 8 deletions custom_components/hacs/hacsstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import logging
import json
import aiofiles
from custom_components.hacs.aiogithub import AIOGitHubException
from custom_components.hacs.hacsbase import HacsBase
from custom_components.hacs.exceptions import HacsNotSoBasicException, HacsRequirement
from .aiogithub import AIOGitHubException
from .hacsbase import HacsBase
from .exceptions import HacsNotSoBasicException, HacsRequirement
from .const import STORENAME, GENERIC_ERROR, STORAGE_VERSION

_LOGGER = logging.getLogger('custom_components.hacs.storage')

Expand All @@ -15,10 +16,10 @@ class HacsStorage(HacsBase):

async def get(self):
"""Read HACS data to storage."""
from custom_components.hacs.blueprints import (
from .blueprints import (
HacsRepositoryIntegration,
HacsRepositoryPlugin,)
datastore = "{}/.storage/{}".format(self.config_dir, self.const.STORENAME)
datastore = "{}/.storage/{}".format(self.config_dir, STORENAME)
_LOGGER.debug("Reading from datastore %s.", datastore)

self.data["task_running"] = True
Expand Down Expand Up @@ -68,7 +69,7 @@ async def get(self):
elif repository_type == "plugin":
repository = HacsRepositoryPlugin(repository.full_name, repository)
else:
raise HacsNotSoBasicException(self.const.GENERIC_ERROR)
raise HacsNotSoBasicException(GENERIC_ERROR)

# Initial setup.
try:
Expand All @@ -92,11 +93,11 @@ async def get(self):
async def set(self):
"""Write HACS data to storage."""
_LOGGER.info("Saving data")
datastore = "{}/.storage/{}".format(self.config_dir, self.const.STORENAME)
datastore = "{}/.storage/{}".format(self.config_dir, STORENAME)

data = {}
data["hacs"] = self.data["hacs"]
data["hacs"]["schema"] = self.const.STORAGE_VERSION
data["hacs"]["schema"] = STORAGE_VERSION

data["repositories"] = {}

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/hacsviewbase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Blueprint for HacsViewBase."""
from homeassistant.components.http import HomeAssistantView
from custom_components.hacs.hacsbase import HacsBase
from .hacsbase import HacsBase


class HacsViewBase(HomeAssistantView, HacsBase):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/handler/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import aiofiles

from custom_components.hacs.const import STARTUP
from ..const import STARTUP

_LOGGER = logging.getLogger('custom_components.hacs.log')

Expand Down

0 comments on commit 5f21c71

Please sign in to comment.