Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemco Burema <r.burema@ultimaker.com>2018-10-11 22:54:27 +0300
committerRemco Burema <r.burema@ultimaker.com>2018-10-11 22:54:27 +0300
commitf2b50c748c1aea35e61de119fb3a08a28afdb295 (patch)
tree26968ce2d6e9a59cea1e0ab6641a0f52b2b73179 /plugins/FirmwareUpdateChecker
parent839016d2f3d46ac0af8578bc30e99921121dcfc4 (diff)
Fix typing in the FirmwareUpdateChecker plugin.
Diffstat (limited to 'plugins/FirmwareUpdateChecker')
-rw-r--r--plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py14
-rw-r--r--plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py5
-rw-r--r--plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py30
3 files changed, 28 insertions, 21 deletions
diff --git a/plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py b/plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py
index 90590fc5a2..71bdd0bc23 100644
--- a/plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py
+++ b/plugins/FirmwareUpdateChecker/FirmwareUpdateChecker.py
@@ -1,10 +1,12 @@
# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
-import json, os
+import os
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QDesktopServices
+from typing import List
+
from UM.Extension import Extension
from UM.Application import Application
from UM.Logger import Logger
@@ -19,12 +21,13 @@ from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup, get_settin
i18n_catalog = i18nCatalog("cura")
+
## This Extension checks for new versions of the firmware based on the latest checked version number.
# 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):
- def __init__(self):
+ def __init__(self) -> None:
super().__init__()
# Listen to a Signal that indicates a change in the list of printers, just if the user has enabled the
@@ -36,7 +39,8 @@ class FirmwareUpdateChecker(Extension):
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 = []
+ self._name_cache = [] # type: List[str]
+ self._lookups = None
## Callback for the message that is spawned when there is a new version.
def _onActionTriggered(self, message, action):
@@ -46,8 +50,8 @@ class FirmwareUpdateChecker(Extension):
QDesktopServices.openUrl(QUrl(download_url))
else:
Logger.log('e', "Can't find URL for {0}".format(action))
- except:
- Logger.log('e', "Don't know what to do with {0}".format(action))
+ except Exception as 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
diff --git a/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py b/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py
index 342287ca76..d186cbb4e4 100644
--- a/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py
+++ b/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerJob.py
@@ -9,6 +9,7 @@ from UM.Version import Version
import urllib.request
from urllib.error import URLError
+from typing import Dict
import codecs
from .FirmwareUpdateCheckerLookup import FirmwareUpdateCheckerLookup, get_settings_key_for_machine
@@ -24,14 +25,14 @@ class FirmwareUpdateCheckerJob(Job):
ZERO_VERSION = Version(STRING_ZERO_VERSION)
EPSILON_VERSION = Version(STRING_EPSILON_VERSION)
- def __init__(self, container=None, silent=False, lookups:FirmwareUpdateCheckerLookup=None, callback=None):
+ def __init__(self, container, silent, lookups: FirmwareUpdateCheckerLookup, callback) -> None:
super().__init__()
self._container = container
self.silent = silent
self._callback = callback
self._lookups = lookups
- self._headers = {} # Don't set headers yet.
+ self._headers = {} # type:Dict[str, str] # Don't set headers yet.
def getUrlResponse(self, url: str) -> str:
result = self.STRING_ZERO_VERSION
diff --git a/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py b/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py
index f2c9082f76..f6d7a24da0 100644
--- a/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py
+++ b/plugins/FirmwareUpdateChecker/FirmwareUpdateCheckerLookup.py
@@ -1,7 +1,9 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
-import json, os
+import json
+
+from typing import Callable, Dict, List, Optional
from UM.Logger import Logger
from UM.Version import Version
@@ -22,7 +24,7 @@ def default_parse_version_response(response: str) -> Version:
class FirmwareUpdateCheckerLookup:
JSON_NAME_TO_VERSION_PARSE_FUNCTION = {"default": default_parse_version_response}
- def __init__(self, json_path):
+ def __init__(self, json_path) -> None:
# 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:
@@ -32,11 +34,11 @@ class FirmwareUpdateCheckerLookup:
return
# Parse all the needed lookup-tables from the '.json' file(s) in the resources folder.
- self._machine_ids = []
- self._machine_per_name = {}
- self._parse_version_url_per_machine = {}
- self._check_urls_per_machine = {}
- self._redirect_user_per_machine = {}
+ self._machine_ids = [] # type:List[int]
+ self._machine_per_name = {} # type:Dict[str, int]
+ self._parse_version_url_per_machine = {} # type:Dict[int, Callable]
+ self._check_urls_per_machine = {} # type:Dict[int, List[str]]
+ self._redirect_user_per_machine = {} # type:Dict[int, str]
try:
for machine_json in machines_json:
machine_id = machine_json.get("id")
@@ -53,20 +55,20 @@ class FirmwareUpdateCheckerLookup:
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:
- Logger.log('e', "Couldn't parse firmware-update-check loopup-lists from file.")
+ except Exception as ex:
+ Logger.log('e', "Couldn't parse firmware-update-check loopup-lists from file because {0}.".format(ex))
- def getMachineIds(self) -> [int]:
+ def getMachineIds(self) -> List[int]:
return self._machine_ids
- def getMachineByName(self, machine_name: str) -> int:
+ def getMachineByName(self, machine_name: str) -> Optional[int]:
return self._machine_per_name.get(machine_name)
- def getParseVersionUrlFor(self, machine_id: int) -> str:
+ def getParseVersionUrlFor(self, machine_id: int) -> Optional[Callable]:
return self._parse_version_url_per_machine.get(machine_id)
- def getCheckUrlsFor(self, machine_id: int) -> [str]:
+ def getCheckUrlsFor(self, machine_id: int) -> Optional[List[str]]:
return self._check_urls_per_machine.get(machine_id)
- def getRedirectUserFor(self, machine_id: int) -> str:
+ def getRedirectUserFor(self, machine_id: int) -> Optional[str]:
return self._redirect_user_per_machine.get(machine_id)