Cura/plugins/UM3NetworkPrinting/SendMaterialJob.py
Ghostkeeper 4727340ae4
Send only original files
When we re-serialize them, the XML file will not be exactly the same so the signature will fail to match. We need to send the original bytes.

This changes the behaviour: It now sends all non-default files instead of all files that were loaded fully.

Contributes to issue CURA-5034.
2018-06-08 16:02:00 +02:00

36 lines
No EOL
1.6 KiB
Python

# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import os #To walk over material files.
import os.path #To filter on material files.
from typing import TYPE_CHECKING
from UM.Job import Job #The interface we're implementing.
from UM.Logger import Logger
from UM.Resources import Resources
from cura.CuraApplication import CuraApplication
if TYPE_CHECKING:
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
## Asynchronous job to send material profiles to the printer.
#
# This way it won't freeze up the interface while sending those materials.
class SendMaterialJob(Job):
def __init__(self, device: "NetworkedPrinterDevice"):
super().__init__()
self.device = device
def run(self):
for file_path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.MaterialInstanceContainer):
if not file_path.startswith(Resources.getDataStoragePath() + os.sep):
continue
_, file_name = os.path.split(file_path)
Logger.log("d", "Syncing material profile with printer: {file_name}".format(file_name = file_name))
parts = []
with open(file_path, "rb") as f:
parts.append(self.device._createFormPart("name=\"file\"; filename=\"{file_name}\"".format(file_name = file_name), f.read()))
parts.append(self.device._createFormPart("name=\"filename\"", file_name.encode("utf-8"), "text/plain"))
self.device.postFormWithParts(target = "/materials", parts = parts)