mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Parse the firmware-update-check lookup-tables from a (new) .json instead of hardcoded.
This commit is contained in:
parent
12999f48c8
commit
6c2791f382
3 changed files with 101 additions and 55 deletions
|
@ -1,18 +1,20 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import json, os
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtGui import QDesktopServices
|
||||
|
||||
from UM.Extension import Extension
|
||||
from UM.Application import Application
|
||||
from UM.Logger import Logger
|
||||
from UM.PluginRegistry import PluginRegistry
|
||||
from UM.i18n import i18nCatalog
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
|
||||
from cura.Settings.GlobalStack import GlobalStack
|
||||
|
||||
from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob, MachineId, get_settings_key_for_machine
|
||||
from .FirmwareUpdateCheckerJob import FirmwareUpdateCheckerJob, get_settings_key_for_machine
|
||||
|
||||
i18n_catalog = i18nCatalog("cura")
|
||||
|
||||
|
@ -20,38 +22,23 @@ i18n_catalog = i18nCatalog("cura")
|
|||
# The plugin is currently only usable for applications maintained by Ultimaker. But it should be relatively easy
|
||||
# to change it to work for other applications.
|
||||
class FirmwareUpdateChecker(Extension):
|
||||
JEDI_VERSION_URL = "http://software.ultimaker.com/jedi/releases/latest.version?utm_source=cura&utm_medium=software&utm_campaign=resources"
|
||||
UM_NEW_URL_TEMPLATE = "http://software.ultimaker.com/releases/firmware/{0}/stable/version.txt"
|
||||
VERSION_URLS_PER_MACHINE = \
|
||||
{
|
||||
MachineId.UM3: [JEDI_VERSION_URL, UM_NEW_URL_TEMPLATE.format(MachineId.UM3.value)],
|
||||
MachineId.UM3E: [JEDI_VERSION_URL, UM_NEW_URL_TEMPLATE.format(MachineId.UM3E.value)],
|
||||
MachineId.S5: [UM_NEW_URL_TEMPLATE.format(MachineId.S5.value)]
|
||||
}
|
||||
# The 'new'-style URL is the only way to check for S5 firmware,
|
||||
# and in the future, the UM3 line will also switch over, but for now the old 'JEDI'-style URL is still needed.
|
||||
# TODO: Parse all of that from a file, because this will be a big mess of large static values which gets worse with each printer.
|
||||
# See also the to-do in FirmWareCheckerJob.
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
# Initialize the Preference called `latest_checked_firmware` that stores the last version
|
||||
# checked for each printer.
|
||||
for machine_id in MachineId:
|
||||
Application.getInstance().getPreferences().addPreference(get_settings_key_for_machine(machine_id), "")
|
||||
|
||||
# Listen to a Signal that indicates a change in the list of printers, just if the user has enabled the
|
||||
# 'check for updates' option
|
||||
Application.getInstance().getPreferences().addPreference("info/automatic_update_check", True)
|
||||
if Application.getInstance().getPreferences().getValue("info/automatic_update_check"):
|
||||
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
|
||||
|
||||
self._late_init = True # Init some things after creation, since we need the path from the plugin-mgr.
|
||||
self._download_url = None
|
||||
self._check_job = None
|
||||
self._name_cache = []
|
||||
|
||||
## Callback for the message that is spawned when there is a new version.
|
||||
# TODO: Set the right download URL for each message!
|
||||
def _onActionTriggered(self, message, action):
|
||||
if action == "download":
|
||||
if self._download_url is not None:
|
||||
|
@ -68,6 +55,25 @@ class FirmwareUpdateChecker(Extension):
|
|||
def _onJobFinished(self, *args, **kwargs):
|
||||
self._check_job = None
|
||||
|
||||
def lateInit(self):
|
||||
self._late_init = False
|
||||
|
||||
# Open the .json file with the needed lookup-lists for each machine(/model) and retrieve 'raw' json.
|
||||
self._machines_json = None
|
||||
json_path = os.path.join(PluginRegistry.getInstance().getPluginPath("FirmwareUpdateChecker"),
|
||||
"resources/machines.json")
|
||||
with open(json_path, "r", encoding="utf-8") as json_file:
|
||||
self._machines_json = json.load(json_file).get("machines")
|
||||
if self._machines_json is None:
|
||||
Logger.log('e', "Missing or inaccessible: {0}".format(json_path))
|
||||
return
|
||||
|
||||
# Initialize the Preference called `latest_checked_firmware` that stores the last version
|
||||
# checked for each printer.
|
||||
for machine_json in self._machines_json:
|
||||
machine_id = machine_json.get("id")
|
||||
Application.getInstance().getPreferences().addPreference(get_settings_key_for_machine(machine_id), "")
|
||||
|
||||
## Connect with software.ultimaker.com, load latest.version and check version info.
|
||||
# If the version info is different from the current version, spawn a message to
|
||||
# allow the user to download it.
|
||||
|
@ -75,13 +81,16 @@ class FirmwareUpdateChecker(Extension):
|
|||
# \param silent type(boolean) Suppresses messages other than "new version found" messages.
|
||||
# This is used when checking for a new firmware version at startup.
|
||||
def checkFirmwareVersion(self, container = None, silent = False):
|
||||
if self._late_init:
|
||||
self.lateInit()
|
||||
|
||||
container_name = container.definition.getName()
|
||||
if container_name in self._name_cache:
|
||||
return
|
||||
self._name_cache.append(container_name)
|
||||
|
||||
self._check_job = FirmwareUpdateCheckerJob(container = container, silent = silent,
|
||||
urls = self.VERSION_URLS_PER_MACHINE,
|
||||
machines_json = self._machines_json,
|
||||
callback = self._onActionTriggered,
|
||||
set_download_url_callback = self._onSetDownloadUrl)
|
||||
self._check_job.start()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue