Remove automatic update check (#457)

* Remove automatic update check

* Lint
This commit is contained in:
Otto Winter 2019-02-26 18:31:40 +01:00 committed by GitHub
parent bacddc3673
commit e785ad5401
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 78 deletions

View file

@ -17,8 +17,7 @@ from esphome.core import CORE, EsphomeError
from esphome.cpp_generator import Expression, RawStatement, add, statement from esphome.cpp_generator import Expression, RawStatement, add, statement
from esphome.helpers import color, indent from esphome.helpers import color, indent
from esphome.py_compat import IS_PY2, safe_input, text_type from esphome.py_compat import IS_PY2, safe_input, text_type
from esphome.storage_json import StorageJSON, esphome_storage_path, \ from esphome.storage_json import StorageJSON, storage_path
start_update_check_thread, storage_path
from esphome.util import run_external_command, run_external_process, safe_print from esphome.util import run_external_command, run_external_process, safe_print
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -157,12 +156,7 @@ def write_cpp(config):
def compile_program(args, config): def compile_program(args, config):
_LOGGER.info("Compiling app...") _LOGGER.info("Compiling app...")
update_check = not os.getenv('ESPHOME_NO_UPDATE_CHECK', '')
if update_check:
thread = start_update_check_thread(esphome_storage_path(CORE.config_dir))
rc = platformio_api.run_compile(config, args.verbose) rc = platformio_api.run_compile(config, args.verbose)
if update_check:
thread.join()
return rc return rc

View file

@ -1,10 +1,9 @@
import binascii import binascii
import codecs import codecs
from datetime import datetime, timedelta from datetime import datetime
import json import json
import logging import logging
import os import os
import threading
from esphome import const from esphome import const
from esphome.core import CORE from esphome.core import CORE
@ -226,72 +225,3 @@ class EsphomeStorageJSON(object):
def __eq__(self, o): # type: (Any) -> bool def __eq__(self, o): # type: (Any) -> bool
return isinstance(o, EsphomeStorageJSON) and self.as_dict() == o.as_dict() return isinstance(o, EsphomeStorageJSON) and self.as_dict() == o.as_dict()
@property
def should_do_esphome_update_check(self): # type: () -> bool
if self.last_update_check is None:
return True
return self.last_update_check + timedelta(days=3) < datetime.utcnow()
class CheckForUpdateThread(threading.Thread):
def __init__(self, path):
threading.Thread.__init__(self)
self._path = path
@property
def docs_base(self):
return 'https://beta.esphome.io' if 'b' in const.__version__ else \
'https://esphome.io'
def fetch_remote_version(self):
import requests
storage = EsphomeStorageJSON.load(self._path) or \
EsphomeStorageJSON.get_default()
if not storage.should_do_esphome_update_check:
return storage
req = requests.get('{}/_static/version'.format(self.docs_base))
req.raise_for_status()
storage.remote_version = req.text.strip()
storage.last_update_check = datetime.utcnow()
storage.save(self._path)
return storage
@staticmethod
def format_version(ver):
vstr = '.'.join(map(str, ver.version))
if ver.prerelease:
vstr += ver.prerelease[0] + str(ver.prerelease[1])
return vstr
def cmp_versions(self, storage):
# pylint: disable=no-name-in-module, import-error
from distutils.version import StrictVersion
remote_version = StrictVersion(storage.remote_version)
self_version = StrictVersion(const.__version__)
if remote_version > self_version:
_LOGGER.warning("*" * 80)
_LOGGER.warning("A new version of ESPHome is available: %s (this is %s)",
self.format_version(remote_version), self.format_version(self_version))
_LOGGER.warning("Changelog: %s/changelog/index.html", self.docs_base)
_LOGGER.warning("Update Instructions: %s/guides/faq.html"
"#how-do-i-update-to-the-latest-version", self.docs_base)
_LOGGER.warning("*" * 80)
def run(self):
try:
storage = self.fetch_remote_version()
self.cmp_versions(storage)
except Exception: # pylint: disable=broad-except
pass
def start_update_check_thread(path):
# dummy call to strptime as python 2.7 has a bug with strptime when importing from threads
datetime.strptime('20180101', '%Y%m%d')
thread = CheckForUpdateThread(os.path.abspath(path))
thread.start()
return thread