mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Only load machine_id_to_name.json when it's needed for the first time
This commit is contained in:
parent
484cc6d42f
commit
f665281a6a
@ -31,14 +31,6 @@ CloudApiClientModel = TypeVar("CloudApiClientModel", bound=BaseModel)
|
|||||||
"""The generic type variable used to document the methods below."""
|
"""The generic type variable used to document the methods below."""
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(Path(__file__).parent / "machine_id_to_name.json", "rt") as f:
|
|
||||||
MACHINE_ID_TO_NAME: Dict[str, str] = json.load(f)
|
|
||||||
except Exception as e:
|
|
||||||
Logger.logException("e", f"Could not load machine_id_to_name.json: '{e}'")
|
|
||||||
MACHINE_ID_TO_NAME = {}
|
|
||||||
|
|
||||||
|
|
||||||
class CloudApiClient:
|
class CloudApiClient:
|
||||||
"""The cloud API client is responsible for handling the requests and responses from the cloud.
|
"""The cloud API client is responsible for handling the requests and responses from the cloud.
|
||||||
|
|
||||||
@ -55,6 +47,9 @@ class CloudApiClient:
|
|||||||
# In order to avoid garbage collection we keep the callbacks in this list.
|
# In order to avoid garbage collection we keep the callbacks in this list.
|
||||||
_anti_gc_callbacks = [] # type: List[Callable[[Any], None]]
|
_anti_gc_callbacks = [] # type: List[Callable[[Any], None]]
|
||||||
|
|
||||||
|
# Custom machine definition ID to cloud cluster name mapping
|
||||||
|
_machine_id_to_name: Dict[str, str] = None
|
||||||
|
|
||||||
def __init__(self, app: CuraApplication, on_error: Callable[[List[CloudError]], None]) -> None:
|
def __init__(self, app: CuraApplication, on_error: Callable[[List[CloudError]], None]) -> None:
|
||||||
"""Initializes a new cloud API client.
|
"""Initializes a new cloud API client.
|
||||||
|
|
||||||
@ -93,8 +88,9 @@ class CloudApiClient:
|
|||||||
# conversion!
|
# conversion!
|
||||||
# API points to "MakerBot Method" for a makerbot printertypes which we already changed to allign with other printer_type
|
# API points to "MakerBot Method" for a makerbot printertypes which we already changed to allign with other printer_type
|
||||||
|
|
||||||
if machine_type in MACHINE_ID_TO_NAME:
|
machine_id_to_name = self.getMachineIDMap()
|
||||||
machine_type = MACHINE_ID_TO_NAME[machine_type]
|
if machine_type in machine_id_to_name:
|
||||||
|
machine_type = machine_id_to_name[machine_type]
|
||||||
else:
|
else:
|
||||||
machine_type = machine_type.replace("_plus", "+")
|
machine_type = machine_type.replace("_plus", "+")
|
||||||
machine_type = machine_type.replace("_", " ")
|
machine_type = machine_type.replace("_", " ")
|
||||||
@ -284,3 +280,14 @@ class CloudApiClient:
|
|||||||
|
|
||||||
self._anti_gc_callbacks.append(parse)
|
self._anti_gc_callbacks.append(parse)
|
||||||
return parse
|
return parse
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getMachineIDMap(cls) -> Dict[str, str]:
|
||||||
|
if cls._machine_id_to_name is None:
|
||||||
|
try:
|
||||||
|
with open(Path(__file__).parent / "machine_id_to_name.json", "rt") as f:
|
||||||
|
cls._machine_id_to_name = json.load(f)
|
||||||
|
except Exception as e:
|
||||||
|
Logger.logException("e", f"Could not load machine_id_to_name.json: '{e}'")
|
||||||
|
cls._machine_id_to_name = {}
|
||||||
|
return cls._machine_id_to_name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user