Warn on error and continue on encountering 'future-proof' (now) or old (later) version-URLs.

This commit is contained in:
Remco Burema 2018-10-10 16:52:47 +02:00
parent 10b5584ca6
commit 487ef52c66

View file

@ -10,6 +10,7 @@ from UM.Job import Job
from UM.Version import Version
import urllib.request
from urllib.error import URLError
import codecs
from UM.i18n import i18nCatalog
@ -62,16 +63,20 @@ class FirmwareUpdateCheckerJob(Job):
self._callback = callback
self._set_download_url_callback = set_download_url_callback
application_name = Application.getInstance().getApplicationName()
application_version = Application.getInstance().getVersion()
self._headers = {"User-Agent": "%s - %s" % (application_name, application_version)}
self._headers = {} # Don't set headers yet.
def getUrlResponse(self, url: str) -> str:
result = "0.0.0"
try:
request = urllib.request.Request(url, headers=self._headers)
current_version_file = urllib.request.urlopen(request)
reader = codecs.getreader("utf-8")
result = reader(current_version_file).read(firstline=True)
except URLError:
Logger.log('w', "Could not reach '{0}', if this URL is old, consider removal.".format(url))
return reader(current_version_file).read(firstline=True)
return result
def getCurrentVersionForMachine(self, machine_id: MachineId) -> Version:
max_version = Version([0, 0, 0])
@ -95,6 +100,10 @@ class FirmwareUpdateCheckerJob(Job):
return
try:
application_name = Application.getInstance().getApplicationName()
application_version = Application.getInstance().getVersion()
self._headers = {"User-Agent": "%s - %s" % (application_name, application_version)}
# get machine name from the definition container
machine_name = self._container.definition.getName()
machine_name_parts = machine_name.lower().split(" ")