move default fuction to local fuction + minor fix

This commit is contained in:
Unknown committed 2018-12-18 18:47:16 +01:00
1 parent 054bbead72
commit 5396daa7f6
1 file changed
+12 -11
+12 -11
View File
@@ -653,18 +653,20 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
return []
return map(lambda x: (x[0][1:], x[1]), self._comm.getSdFiles())
def default_add_sd_file(self, printer, filename, remoteName, absolutePath, *args, **kwargs):
self._create_estimator("stream")
self._comm.startFileTransfer(absolutePath, filename, "/" + remoteName,
special=not valid_file_type(filename, "gcode"),
tags=kwargs.get("tags", set()) | {"trigger:printer.add_sd_file"})
return None
def add_sd_file(self, filename, absolutePath, on_success=None, on_failure=None, *args, **kwargs):
if not self._comm or self._comm.isBusy() or not self._comm.isSdReady():
self._logger.error("No connection to printer or printer is busy")
return
def default_add_sd_file(self, printer, filename, remoteName, absolutePath, *args, **kwargs):
self._create_estimator("stream")
self._comm.startFileTransfer(absolutePath, filename, "/" + remoteName,
special=not valid_file_type(filename, "gcode"),
tags=kwargs.get("tags", set()) | {"trigger:printer.add_sd_file"})
return None
self._streamingFinishedCallback = on_success
self._streamingFailedCallback = on_failure
@@ -679,7 +681,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
else:
# probably something else added through a plugin, use it's basename as-is
remoteName = os.path.basename(filename)
default_add_sd_file
sd_card_uploads = self.sd_card_upload_hooks.items() + [("default", self.default_add_sd_file)]
for name, hook in sd_card_uploads:
try:
@@ -691,11 +692,11 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
self._logger.info("run sd card upload with {}".format(name))
#Start calculates total processing time
timestart = time.time()
resultHook = hook(self, filename, remoteName, absolutePath)
if not resultHook is None:
result_hook = hook(self, filename, remoteName, absolutePath)
if result_hook is not None:
payload["time"] = round(time.time() - timestart, 2)
#End calculates total processing time
if resultHook:
if result_hook:
self.on_comm_file_transfer_done(payload["remote"])
eventManager().fire(Events.TRANSFER_DONE, payload)
else:
@@ -703,7 +704,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
#only one impl authorize
break
except:
self._logger.exception("Error while processing analysis queues from {}".format(name))
self._logger.exception("Error while processing copy to sd from {}".format(name))
return remoteName