mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Code style: Use double quotes for strings
Contributes to issue CURA-5483.
This commit is contained in:
parent
69cef98c30
commit
6ac10db582
3 changed files with 18 additions and 18 deletions
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import os
|
||||
|
@ -31,7 +31,7 @@ class FirmwareUpdateChecker(Extension):
|
|||
super().__init__()
|
||||
|
||||
# Listen to a Signal that indicates a change in the list of printers, just if the user has enabled the
|
||||
# 'check for updates' option
|
||||
# "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)
|
||||
|
@ -49,9 +49,9 @@ class FirmwareUpdateChecker(Extension):
|
|||
if download_url is not None:
|
||||
QDesktopServices.openUrl(QUrl(download_url))
|
||||
else:
|
||||
Logger.log('e', "Can't find URL for {0}".format(action))
|
||||
Logger.log("e", "Can't find URL for {0}".format(action))
|
||||
except Exception as ex:
|
||||
Logger.log('e', "Don't know what to do with '{0}' because {1}".format(action, ex))
|
||||
Logger.log("e", "Don't know what to do with '{0}' because {1}".format(action, ex))
|
||||
|
||||
def _onContainerAdded(self, container):
|
||||
# Only take care when a new GlobalStack was added
|
||||
|
|
|
@ -40,9 +40,9 @@ class FirmwareUpdateCheckerJob(Job):
|
|||
try:
|
||||
request = urllib.request.Request(url, headers=self._headers)
|
||||
response = urllib.request.urlopen(request)
|
||||
result = response.read().decode('utf-8')
|
||||
result = response.read().decode("utf-8")
|
||||
except URLError:
|
||||
Logger.log('w', "Could not reach '{0}', if this URL is old, consider removal.".format(url))
|
||||
Logger.log("w", "Could not reach '{0}', if this URL is old, consider removal.".format(url))
|
||||
|
||||
return result
|
||||
|
||||
|
@ -58,7 +58,7 @@ class FirmwareUpdateCheckerJob(Job):
|
|||
max_version = version
|
||||
|
||||
if max_version < self.EPSILON_VERSION:
|
||||
Logger.log('w', "MachineID {0} not handled!".format(repr(machine_id)))
|
||||
Logger.log("w", "MachineID {0} not handled!".format(repr(machine_id)))
|
||||
|
||||
return max_version
|
||||
|
||||
|
@ -82,11 +82,11 @@ class FirmwareUpdateCheckerJob(Job):
|
|||
|
||||
current_version = self.getCurrentVersionForMachine(machine_id)
|
||||
|
||||
# If it is the first time the version is checked, the checked_version is ''
|
||||
# If it is the first time the version is checked, the checked_version is ""
|
||||
setting_key_str = get_settings_key_for_machine(machine_id)
|
||||
checked_version = Version(Application.getInstance().getPreferences().getValue(setting_key_str))
|
||||
|
||||
# If the checked_version is '', it's because is the first time we check firmware and in this case
|
||||
# If the checked_version is "", it's because is the first time we check firmware and in this case
|
||||
# we will not show the notification, but we will store it for the next time
|
||||
Application.getInstance().getPreferences().setValue(setting_key_str, current_version)
|
||||
Logger.log("i", "Reading firmware version of %s: checked = %s - latest = %s", machine_name, checked_version, current_version)
|
||||
|
@ -115,7 +115,7 @@ class FirmwareUpdateCheckerJob(Job):
|
|||
message.actionTriggered.connect(self._callback)
|
||||
message.show()
|
||||
else:
|
||||
Logger.log('i', "No machine with name {0} in list of firmware to check.".format(machine_name))
|
||||
Logger.log("i", "No machine with name {0} in list of firmware to check.".format(machine_name))
|
||||
|
||||
except Exception as e:
|
||||
Logger.log("w", "Failed to check for new version: %s", e)
|
||||
|
|
|
@ -17,23 +17,23 @@ def get_settings_key_for_machine(machine_id: int) -> str:
|
|||
|
||||
|
||||
def default_parse_version_response(response: str) -> Version:
|
||||
raw_str = response.split('\n', 1)[0].rstrip()
|
||||
return Version(raw_str.split('.')) # Split it into a list; the default parsing of 'single string' is different.
|
||||
raw_str = response.split("\n", 1)[0].rstrip()
|
||||
return Version(raw_str.split(".")) # Split it into a list; the default parsing of "single string" is different.
|
||||
|
||||
|
||||
class FirmwareUpdateCheckerLookup:
|
||||
JSON_NAME_TO_VERSION_PARSE_FUNCTION = {"default": default_parse_version_response}
|
||||
|
||||
def __init__(self, json_path) -> None:
|
||||
# Open the .json file with the needed lookup-lists for each machine(/model) and retrieve 'raw' json.
|
||||
# Open the .json file with the needed lookup-lists for each machine(/model) and retrieve "raw" json.
|
||||
machines_json = None
|
||||
with open(json_path, "r", encoding="utf-8") as json_file:
|
||||
machines_json = json.load(json_file).get("machines")
|
||||
if machines_json is None:
|
||||
Logger.log('e', "Missing or inaccessible: {0}".format(json_path))
|
||||
Logger.log("e", "Missing or inaccessible: {0}".format(json_path))
|
||||
return
|
||||
|
||||
# Parse all the needed lookup-tables from the '.json' file(s) in the resources folder.
|
||||
# Parse all the needed lookup-tables from the ".json" file(s) in the resources folder.
|
||||
self._machine_ids = [] # type:List[int]
|
||||
self._machine_per_name = {} # type:Dict[str, int]
|
||||
self._parse_version_url_per_machine = {} # type:Dict[int, Callable]
|
||||
|
@ -48,15 +48,15 @@ class FirmwareUpdateCheckerLookup:
|
|||
version_parse_function = \
|
||||
self.JSON_NAME_TO_VERSION_PARSE_FUNCTION.get(machine_json.get("version_parser"))
|
||||
if version_parse_function is None:
|
||||
Logger.log('w', "No version-parse-function specified for machine {0}.".format(machine_name))
|
||||
Logger.log("w", "No version-parse-function specified for machine {0}.".format(machine_name))
|
||||
version_parse_function = default_parse_version_response # Use default instead if nothing is found.
|
||||
self._parse_version_url_per_machine[machine_id] = version_parse_function
|
||||
self._check_urls_per_machine[machine_id] = [] # Multiple check-urls: see '_comment' in the .json file.
|
||||
self._check_urls_per_machine[machine_id] = [] # Multiple check-urls: see "_comment" in the .json file.
|
||||
for check_url in machine_json.get("check_urls"):
|
||||
self._check_urls_per_machine[machine_id].append(check_url)
|
||||
self._redirect_user_per_machine[machine_id] = machine_json.get("update_url")
|
||||
except Exception as ex:
|
||||
Logger.log('e', "Couldn't parse firmware-update-check loopup-lists from file because {0}.".format(ex))
|
||||
Logger.log("e", "Couldn't parse firmware-update-check loopup-lists from file because {0}.".format(ex))
|
||||
|
||||
def getMachineIds(self) -> List[int]:
|
||||
return self._machine_ids
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue