From 5396daa7f6e7fb2e32d2f251ae0fc133546aebb3 Mon Sep 17 00:00:00 2001 From: Unknown <8700106+devildant@users.noreply.github.com> Date: Tue, 18 Dec 2018 18:47:16 +0100 Subject: [PATCH] move default fuction to local fuction + minor fix --- src/octoprint/printer/standard.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index bb03fba94..41d8119e1 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -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