mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Warn on error and continue on encountering 'future-proof' (now) or old (later) version-URLs.
This commit is contained in:
parent
10b5584ca6
commit
487ef52c66
1 changed files with 16 additions and 7 deletions
|
@ -10,6 +10,7 @@ from UM.Job import Job
|
||||||
from UM.Version import Version
|
from UM.Version import Version
|
||||||
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
from urllib.error import URLError
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
|
@ -62,16 +63,20 @@ class FirmwareUpdateCheckerJob(Job):
|
||||||
self._callback = callback
|
self._callback = callback
|
||||||
self._set_download_url_callback = set_download_url_callback
|
self._set_download_url_callback = set_download_url_callback
|
||||||
|
|
||||||
application_name = Application.getInstance().getApplicationName()
|
self._headers = {} # Don't set headers yet.
|
||||||
application_version = Application.getInstance().getVersion()
|
|
||||||
self._headers = {"User-Agent": "%s - %s" % (application_name, application_version)}
|
|
||||||
|
|
||||||
def getUrlResponse(self, url: str) -> str:
|
def getUrlResponse(self, url: str) -> str:
|
||||||
request = urllib.request.Request(url, headers=self._headers)
|
result = "0.0.0"
|
||||||
current_version_file = urllib.request.urlopen(request)
|
|
||||||
reader = codecs.getreader("utf-8")
|
|
||||||
|
|
||||||
return reader(current_version_file).read(firstline=True)
|
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 result
|
||||||
|
|
||||||
def getCurrentVersionForMachine(self, machine_id: MachineId) -> Version:
|
def getCurrentVersionForMachine(self, machine_id: MachineId) -> Version:
|
||||||
max_version = Version([0, 0, 0])
|
max_version = Version([0, 0, 0])
|
||||||
|
@ -95,6 +100,10 @@ class FirmwareUpdateCheckerJob(Job):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
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
|
# get machine name from the definition container
|
||||||
machine_name = self._container.definition.getName()
|
machine_name = self._container.definition.getName()
|
||||||
machine_name_parts = machine_name.lower().split(" ")
|
machine_name_parts = machine_name.lower().split(" ")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue