Upload to SD is now working

This commit is contained in:
Gina Häußge committed 2018-06-14 18:54:40 +02:00
1 parent 473d4a752a
commit 1a67b5b3fc
7 files changed
+242 -120

No files matched your search

+76 -9
View File
@@ -6,7 +6,7 @@ import os
import time
import copy
from octoprint.comm.protocol import ProtocolListener, FileAwareProtocolListener, ProtocolState
from octoprint.comm.protocol import ProtocolListener, FileAwareProtocolListener, ProtocolState, FileManagementProtocolMixin
from octoprint.util.listener import ListenerAware
@@ -118,14 +118,17 @@ class Printjob(ProtocolListener, ListenerAware):
def process_job_done(self):
self.notify_listeners("on_job_done", self)
self.report_stats()
self.reset_job()
def process_job_failed(self):
self.notify_listeners("on_job_failed", self)
self.report_stats()
self.reset_job()
def process_job_cancelled(self):
self.notify_listeners("on_job_cancelled", self)
self.report_stats()
self.reset_job()
def process_job_paused(self):
@@ -137,6 +140,11 @@ class Printjob(ProtocolListener, ListenerAware):
def process_job_progress(self):
self.notify_listeners("on_job_progress", self)
def report_stats(self):
elapsed = self.elapsed
if elapsed:
self._logger.info("Job processed in {}s".format(elapsed))
def reset_job(self):
self._start = None
@@ -296,6 +304,14 @@ class LocalFilePrintjob(StoragePrintjob):
self.close()
self._pos = self._read_lines = 0
def report_stats(self):
elapsed = self.elapsed
lines = self._read_lines
if elapsed and lines:
self._logger.info("Job processed in {:.3f}s ({} lines)".format(elapsed, lines))
class LocalGcodeFilePrintjob(LocalFilePrintjob):
def can_process(self, protocol):
@@ -319,15 +335,66 @@ class LocalGcodeFilePrintjob(LocalFilePrintjob):
return processed
class LocalGcodeStreamjob(LocalGcodeFilePrintjob):
class CopyJobMixin(object):
pass
class LocalGcodeStreamjob(LocalGcodeFilePrintjob, CopyJobMixin):
@classmethod
def from_job(cls, job, remote):
if not isinstance(job, LocalGcodeFilePrintjob):
raise ValueError("job must be a LocalGcodeFilePrintjob")
path = job._path
storage = job._storage
path_in_storage = job._path_in_storage
name = job._name
user = job._user
encoding = job._encoding
event_data = job._event_data
return cls(remote, path, storage, path_in_storage,
name=name, user=user, encoding=encoding, event_data=event_data)
def __init__(self, remote, *args, **kwargs):
super(LocalGcodeStreamjob, self).__init__(*args, **kwargs)
self._remote = remote
@property
def remote(self):
return self._remote
def process(self, protocol, position=0, tags=None):
super(LocalGcodeStreamjob, self).process(protocol, position=position, tags=tags)
self._protocol.record_file(self._remote)
def process_job_done(self):
self._protocol.stop_recording_file()
super(LocalGcodeStreamjob, self).process_job_done()
def process_job_failed(self):
self._protocol.stop_recording_file()
super(LocalGcodeStreamjob, self).process_job_failed()
def process_job_cancelled(self):
self._protocol.stop_recording_file()
self._protocol.delete_file(self.remote)
super(LocalGcodeStreamjob, self).process_job_cancelled()
def can_process(self, protocol):
from octoprint.comm.protocol import FileStreamingProtocolMixin
return LocalGcodeStreamjob in protocol.supported_jobs and isinstance(protocol, FileStreamingProtocolMixin)
return LocalGcodeStreamjob in protocol.supported_jobs and isinstance(protocol, FileStreamingProtocolMixin) and isinstance(protocol, FileManagementProtocolMixin)
def process_line(self, line):
# we do not change anything for sd file streaming
return line
def report_stats(self):
elapsed = self.elapsed
lines = self._read_lines
if elapsed and lines:
self._logger.info("Job processed in {:.3f}s ({} lines). Approx. {:.3f} lines/s, {:.3f} ms/line".format(elapsed,
lines,
float(lines) / float(elapsed),
float(elapsed) * 1000.0 / float(lines)))
class SDFilePrintjob(StoragePrintjob, FileAwareProtocolListener):
@@ -387,16 +454,16 @@ class SDFilePrintjob(StoragePrintjob, FileAwareProtocolListener):
self._status_timer = RepeatedTimer(self._status_interval, self._query_status, condition=self._query_active)
self._status_timer.start()
def on_protocol_file_status(self, protocol, pos, total):
def on_protocol_file_status(self, protocol, pos, total, *args, **kwargs):
self._last_pos = pos
self._size = total
self.process_job_progress()
def on_protocol_file_print_started(self, protocol, name, size):
def on_protocol_file_print_started(self, protocol, name, size, *args, **kwargs):
self._size = size
self.process_job_started()
def on_protocol_file_print_done(self, protocol):
def on_protocol_file_print_done(self, protocol, *args, **kwargs):
self.process_job_done()
def reset_job(self):
+1 -1
View File
@@ -340,7 +340,7 @@ class FileManagementProtocolMixin(FileAwareProtocolMixin):
class FileStreamingProtocolMixin(FileManagementProtocolMixin):
def record_file(self, name, job):
def record_file(self, name):
pass
def stop_recording_file(self):
+37 -32
View File
@@ -21,7 +21,7 @@ from octoprint.comm.protocol.reprap.util import normalize_command_handler_result
from octoprint.comm.protocol.reprap.util.queues import ScriptQueue, CommandQueue, SendQueue, QueueMarker, SendQueueMarker
from octoprint.comm.job import LocalGcodeFilePrintjob, SDFilePrintjob, \
LocalGcodeStreamjob
LocalGcodeStreamjob, CopyJobMixin
from octoprint.util import TypedQueue, TypeAlreadyInQueue, ResettableTimer, to_str, to_unicode, protectedkeydict, CountedEvent, monotonic_time
@@ -341,8 +341,6 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
if self._job is None:
return
# TODO cancel file streaming
if tags is None:
tags = set()
@@ -366,7 +364,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
self._job.cancel(error=error)
self.notify_listeners("on_protocol_job_cancelling", self, self._job)
if log_position:
if log_position and not isinstance(self._job, CopyJobMixin):
self.send_commands(self.flavor.command_finish_moving(),
on_sent=on_move_finish_requested,
tags=tags | {"trigger:comm.cancel",
@@ -412,6 +410,9 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
if self._job is None or self.state != ProtocolState.PROCESSING:
return
if isinstance(self._job, CopyJobMixin):
return
if tags is None:
tags = set()
@@ -456,7 +457,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
else:
super(ReprapGcodeProtocol, self).resume_processing(tags=tags)
def move(self, x=None, y=None, z=None, e=None, feedrate=None, relative=False):
def move(self, x=None, y=None, z=None, e=None, feedrate=None, relative=False, *args, **kwargs):
commands = [self.flavor.command_move(x=x, y=y, z=z, e=e, f=feedrate)]
if relative:
@@ -466,65 +467,65 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
self._send_commands(*commands)
def home(self, x=False, y=False, z=False):
def home(self, x=False, y=False, z=False, *args, **kwargs):
self._send_commands(self.flavor.command_home(x=x, y=y, z=z))
def change_tool(self, tool):
def change_tool(self, tool, *args, **kwargs):
self._send_commands(self.flavor.command_set_tool(tool))
def set_feedrate_multiplier(self, multiplier):
def set_feedrate_multiplier(self, multiplier, *args, **kwargs):
self._send_commands(self.flavor.command_set_feedrate_multiplier(multiplier))
def set_extrusion_multiplier(self, multiplier):
def set_extrusion_multiplier(self, multiplier, *args, **kwargs):
self._send_commands(self.flavor.command_set_extrusion_multiplier(multiplier))
def set_extruder_temperature(self, temperature, tool=None, wait=False):
def set_extruder_temperature(self, temperature, tool=None, wait=False, *args, **kwargs):
self._send_commands(self.flavor.command_set_extruder_temp(temperature, tool, wait=wait))
def set_bed_temperature(self, temperature, wait=False):
def set_bed_temperature(self, temperature, wait=False, *args, **kwargs):
self._send_commands(self.flavor.command_set_bed_temp(temperature, wait=wait))
##~~ MotorControlProtocolMixin
def set_motor_state(self, enabled):
def set_motor_state(self, enabled, *args, **kwargs):
self._send_commands(self.flavor.command.set_motor_state(enabled))
##~~ FanControlProtocolMixin
def set_fan_speed(self, speed):
def set_fan_speed(self, speed, *args, **kwargs):
self._send_commands(self.flavor.command.command_set_fan_speed(speed))
##~~ FileStreamingProtocolMixin
def init_file_storage(self):
def init_file_storage(self, *args, **kwargs):
self._send_commands(self.flavor.command_sd_init())
def list_files(self):
def list_files(self, *args, **kwargs):
self._send_commands(self.flavor.command_sd_refresh())
def start_file_print(self, name, position=0, **kwargs):
def start_file_print(self, name, position=0, *args, **kwargs):
tags = kwargs.get(b"tags", set()) | {"trigger:protocol.start_file_print"}
self._send_commands(self.flavor.command_sd_select_file(name),
self.flavor.command_sd_set_pos(position),
self.flavor.command_sd_start(),
tags=tags)
def pause_file_print(self):
def pause_file_print(self, *args, **kwargs):
self._send_commands(self.flavor.command_sd_pause())
def resume_file_print(self):
def resume_file_print(self, *args, **kwargs):
self._send_commands(self.flavor.command_sd_resume())
def delete_file(self, name):
def delete_file(self, name, *args, **kwargs):
self._send_commands(self.flavor.command_sd_delete(name))
def record_file(self, name, job):
def record_file(self, name, *args, **kwargs):
self._send_commands(self.flavor.command_sd_begin_write(name))
def stop_recording_file(self):
def stop_recording_file(self, *args, **kwargs):
self._send_commands(self.flavor.command_sd_end_write())
def get_file_print_status(self):
def get_file_print_status(self, *args, **kwargs):
self._send_commands(self.flavor.command_sd_status())
def can_send(self):
@@ -557,7 +558,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
elif self._is_operational() or force:
self._send_commands(*commands, on_sent=on_sent, command_type=command_type, tags=tags)
def send_script(self, script, context=None):
def send_script(self, script, context=None, *args, **kwargs):
if context is None:
context = dict()
@@ -576,7 +577,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
"source:script",
"script:{}".format(script.name)}, *lines)
def repair(self):
def repair(self, *args, **kwargs):
self._on_comm_ok()
##~~ State handling
@@ -652,7 +653,9 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
##~~ Job handling
def on_job_cancelled(self, job):
pass
if job != self._job:
return
self._job_processed(job)
def on_job_paused(self, job, *args, **kwargs):
pass
@@ -662,8 +665,8 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
return
self.state = ProtocolState.FINISHING
self.notify_listeners("on_protocol_job_finishing", self, job)
self._job_processed(job)
self.notify_listeners("on_protocol_job_finishing", self, job)
def finalize():
self.state = ProtocolState.CONNECTED
@@ -1157,9 +1160,11 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
def _on_message_sd_init_ok(self):
self._internal_flags["sd_available"] = True
self.list_files()
self.notify_listeners("on_protocol_file_storage_available", self, self._internal_flags["sd_available"])
def _on_message_sd_init_fail(self):
self._internal_flags["sd_available"] = False
self.notify_listeners("on_protocol_file_storage_available", self, self._internal_flags["sd_available"])
def _on_message_sd_begin_file_list(self):
self._internal_flags["sd_files_temp"] = []
@@ -1167,13 +1172,13 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
def _on_message_sd_end_file_list(self):
self._internal_flags["sd_files"] = self._internal_flags["sd_files_temp"]
self._internal_flags["sd_files_temp"] = None
self.notify_listeners("on_protocol_sd_file_list", self, self._internal_flags["sd_files"])
self.notify_listeners("on_protocol_file_list", self, self._internal_flags["sd_files"])
def _on_message_sd_entry(self, name, size):
self._internal_flags["sd_files_temp"].append((name, size))
def _on_message_sd_entry(self, name, long_name, size):
self._internal_flags["sd_files_temp"].append((name, long_name, size))
def _on_message_sd_file_opened(self, name, size):
self.notify_listeners("on_protocol_file_print_started", self, name, size)
def _on_message_sd_file_opened(self, name, long_name, size):
self.notify_listeners("on_protocol_file_print_started", self, name, long_name, size)
def _on_message_sd_done_printing(self):
self.notify_listeners("on_protocol_file_print_done", self)
@@ -1600,7 +1605,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
self._log_command_phase(phase, command)
if phase not in ("queuing", "queued", "sending", "sent"):
if not self._internal_flags["trigger_events"] or phase not in ("queuing", "queued", "sending", "sent"):
return results
# send it through the phase specific handlers provided by plugins
@@ -347,7 +347,10 @@ class GenericFlavor(object):
match = cls.regex_sd_file_opened.match(lower_line)
if not match:
return
return dict(name=match.group(b"name"), size=int(match.group(b"size")))
name = match.group(b"name")
size = int(match.group(b"size"))
return dict(name=name, long_name=name, size=size)
@classmethod
def parse_message_sd_entry(cls, line, lower_line, state, flags):
@@ -375,7 +378,7 @@ class GenericFlavor(object):
# file from the root of the sd -- we'll prepend a /
filename = "/" + filename
return dict(name=filename, size=int(size) if size is not None else None)
return dict(name=filename, long_name=filename, size=int(size) if size is not None else None)
@classmethod
def parse_message_sd_printing_byte(cls, line, lower_line, state, flags):
+1 -1
View File
@@ -444,7 +444,7 @@ class LocalFileStorage(Storage):
return LocalGcodeFilePrintjob(self.path_on_disk(path),
"local",
self.path_in_storage(path),
name=path,
name=self.path_in_storage(path),
user=user,
event_data=dict(path=path,
name=self.split_path(path)[1],
+121 -74
View File
@@ -32,7 +32,7 @@ from octoprint.util import InvariantContainer
from octoprint.util import to_unicode
from octoprint.comm.protocol import ProtocolListener, FileAwareProtocolListener, PositionAwareProtocolListener, ProtocolState
from octoprint.comm.job import StoragePrintjob, LocalGcodeFilePrintjob, LocalGcodeStreamjob, SDFilePrintjob
from octoprint.comm.job import StoragePrintjob, LocalGcodeFilePrintjob, LocalGcodeStreamjob, SDFilePrintjob, CopyJobMixin
from octoprint.comm.protocol.reprap.scripts import GcodeScript
from collections import namedtuple
@@ -104,11 +104,11 @@ class Printer(PrinterInterface,
self._current_z = None
# sd handling
self._sdPrinting = False
self._sdStreaming = False
self._sd_printing = False
self._sd_streaming = False
self._sd_filelist_available = threading.Event()
self._streamingFinishedCallback = None
self._streamingFailedCallback = None
self._on_streaming_done = None
self._on_streaming_failed = None
self._sd_ready = False
self._sd_files = []
@@ -124,9 +124,8 @@ class Printer(PrinterInterface,
self._estimator_factory = estimator
except:
self._logger.exception("Error while processing analysis queues from {}".format(name))
# comm
self._comm = None
# comm
self._protocol = None
self._transport = None
self._job = None
@@ -603,8 +602,8 @@ class Printer(PrinterInterface,
def log_lines(self, *lines):
serial_logger = logging.getLogger("SERIAL")
self.on_comm_log("\n".join(lines))
for line in lines:
self.on_protocol_log(self._protocol, line)
serial_logger.debug(line)
def get_state_string(self, state=None, *args, **kwargs):
@@ -723,19 +722,19 @@ class Printer(PrinterInterface,
return self._protocol is not None and self._protocol.state == ProtocolState.PROCESSING
def is_cancelling(self, *args, **kwargs):
return self._comm is not None and self._comm.isCancelling()
return self._protocol is not None and self._protocol.state == ProtocolState.CANCELLING
def is_pausing(self, *args, **kwargs):
return self._comm is not None and self._comm.isPausing()
return self._protocol is not None and self._protocol.state == ProtocolState.PAUSING
def is_paused(self, *args, **kwargs):
return self._protocol is not None and self._protocol.state == ProtocolState.PAUSED
def is_resuming(self, *args, **kwargs):
return self._comm is not None and self._comm.isResuming()
return self._protocol is not None and self._protocol.state == ProtocolState.RESUMING
def is_finishing(self, *args, **kwargs):
return self._comm is not None and self._comm.isFinishing()
return self._protocol is not None and self._protocol.state == ProtocolState.FINISHING
def is_error(self, *args, **kwargs):
return self._protocol is not None and self._protocol.state == ProtocolState.DISCONNECTED_WITH_ERROR
@@ -754,37 +753,36 @@ class Printer(PrinterInterface,
def get_sd_files(self, *args, **kwargs):
if not self.is_connected() or not self.is_sd_ready():
return []
return map(lambda x: (x[0][1:], x[1]), self._sd_files)
return map(lambda x: (x[0][1:], x[2]), self._sd_files)
def add_sd_file(self, filename, absolutePath, on_success=None, on_failure=None, *args, **kwargs):
# TODO
if not self._protocol or self._protocol.state in ProtocolState.PROCESSING_STATES or not self.is_sd_ready():
self._logger.error("No connection to printer, printer busy or missing SD support")
return
# 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
self._on_streaming_done = on_success
self._on_streaming_failed = on_failure
# self._streamingFinishedCallback = on_success
# self._streamingFailedCallback = on_failure
files = self.refresh_sd_files(blocking=True)
existingSdFiles = map(lambda x: x[0], files)
# self.refresh_sd_files(blocking=True)
# existingSdFiles = map(lambda x: x[0], self._comm.getSdFiles())
if valid_file_type(filename, "gcode"):
remoteName = util.get_dos_filename(filename,
existing_filenames=existingSdFiles,
extension="gco",
whitelisted_extensions=["gco", "g"])
else:
# probably something else added through a plugin, use it's basename as-is
remoteName = os.path.basename(filename)
# if valid_file_type(filename, "gcode"):
# remoteName = util.get_dos_filename(filename,
# existing_filenames=existingSdFiles,
# extension="gco",
# whitelisted_extensions=["gco", "g"])
# else:
# # probably something else added through a plugin, use it's basename as-is
# remoteName = os.path.basename(filename)
# 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"})
job = LocalGcodeStreamjob.from_job(self._file_manager.create_print_job("local", absolutePath, user=kwargs.get("user")),
"/" + remoteName)
self._sd_streaming = True
self._update_job(job)
self._reset_progress_data()
self._protocol.process(job)
# return remoteName
return "foo"
return remoteName
def delete_sd_file(self, filename, *args, **kwargs):
if not self._protocol or not self.is_sd_ready():
@@ -807,12 +805,13 @@ class Printer(PrinterInterface,
available). Optional blocking parameter allows making the method block (max 10s) until the file list has been
received. Defaults to an asynchronous operation.
"""
if self.is_connected() or not self.is_sd_ready():
return
if not self.is_connected() or not self.is_sd_ready():
return []
self._sd_filelist_available.clear()
self._protocol.list_files(tags=kwargs.get("tags", set()) | {"trigger:printer.refresh_sd_files"})
if blocking:
self._sd_filelist_available.wait(kwargs.get("timeout", 10000))
return self._sd_files
#~~ state monitoring
@@ -969,7 +968,7 @@ class Printer(PrinterInterface,
display_name = job.name
if isinstance(job, LocalGcodeFilePrintjob):
if isinstance(job, LocalGcodeFilePrintjob) and not isinstance(job, CopyJobMixin):
# local file means we might have some information about the job stored in the file manager!
try:
file_data = self._file_manager.get_metadata(FileDestinations.LOCAL, job.path)
@@ -1152,6 +1151,9 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if self._job_event_handled(protocol, job, "processing"):
return
payload = job.event_payload()
if payload:
eventManager().fire(Events.PRINT_STARTED, payload)
@@ -1167,49 +1169,50 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if isinstance(self._job.job, LocalGcodeStreamjob):
# streaming job
if self._job_event_handled(protocol, job, "finishing"):
return
if self._streamingFinishedCallback is not None:
# in case of SD files, both filename and absolutePath are the same, so we set the (remote) filename for
# both parameters
self._streamingFinishedCallback(self._job.job.name, self._job.job.name, FileDestinations.SDCARD)
payload = job.event_payload()
if payload:
payload["time"] = job.elapsed
self._update_progress_data(completion=100,
filepos=payload["size"],
print_time=payload["time"],
print_time_left=0)
self._state_monitor.set_state(self._dict(text=self.get_state_string(),
flags=self._get_state_flags()))
self._set_current_z(None)
self._update_job()
self._update_progress_data()
eventManager().fire(Events.PRINT_DONE, payload)
if not suppress_script:
self.script("afterPrintDone",
context=dict(event=payload),
must_be_set=False)
else:
# all other job types
def on_protocol_job_done(self, protocol, job, suppress_scripts=False, *args, **kwargs):
if protocol != self._protocol:
return
payload = job.event_payload()
if payload:
payload["time"] = job.elapsed
self._update_progress_data(completion=100,
filepos=payload["size"],
print_time=payload["time"],
print_time_left=0)
self._state_monitor.set_state(self._dict(text=self.get_state_string(),
flags=self._get_state_flags()))
if self._job is None or job != self._job.job:
return
eventManager().fire(Events.PRINT_DONE, payload)
if not suppress_script:
self.script("afterPrintDone",
context=dict(event=payload),
must_be_set=False)
if self._job_event_handled(protocol, job, "done"):
return
def log_print():
self._file_manager.log_print(payload["origin"],
payload["path"],
time.time(),
payload["time"],
True,
self._printer_profile_manager.get_current_or_default()["id"])
payload = job.event_payload()
if payload:
payload["time"] = job.elapsed
thread = threading.Thread(target=log_print)
thread.daemon = True
thread.start()
def log_print():
self._file_manager.log_print(payload["origin"],
payload["path"],
time.time(),
payload["time"],
True,
self._printer_profile_manager.get_current_or_default()["id"])
thread = threading.Thread(target=log_print)
thread.daemon = True
thread.start()
def on_protocol_job_failed(self, protocol, job, *args, **kwargs):
if protocol != self._protocol:
@@ -1218,6 +1221,9 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if self._job_event_handled(protocol, job, "failed"):
return
payload = job.event_payload()
if payload:
eventManager().fire(Events.PRINT_FAILED, payload)
@@ -1229,6 +1235,9 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if self._job_event_handled(protocol, job, "cancelling"):
return
firmware_error = kwargs.get("error", None)
cancel_position = kwargs.get("position", None)
suppress_scripts = kwargs.get("suppress_scripts", None)
@@ -1253,6 +1262,9 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if self._job_event_handled(protocol, job, "cancelled"):
return
self._update_progress_data()
cancel_position = kwargs.get("position", None)
@@ -1285,6 +1297,9 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if self._job_event_handled(protocol, job, "pausing"):
return
pause_position = kwargs.get("position", None)
suppress_scripts = kwargs.get("suppress_scripts", None)
@@ -1305,6 +1320,9 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if self._job_event_handled(protocol, job, "paused"):
return
pause_position = kwargs.get("position", None)
payload = job.event_payload()
@@ -1320,6 +1338,9 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if self._job_event_handled(protocol, job, "resuming"):
return
suppress_scripts = kwargs.get("suppress_scripts", False)
payload = job.event_payload()
@@ -1335,10 +1356,36 @@ class Printer(PrinterInterface,
if self._job is None or job != self._job.job:
return
if self._job_event_handled(protocol, job, "resumed"):
return
payload = job.event_payload()
if payload:
eventManager().fire(Events.PRINT_RESUMED, payload)
def _job_event_handled(self, protocol, job, event_type):
if not isinstance(job, LocalGcodeStreamjob):
return False
if event_type == "processing":
eventManager().fire(Events.TRANSFER_STARTED, {"local": job.name, "remote": job.remote})
elif event_type in ("done", "cancelled"):
self._sd_streaming = False
self._set_current_z(None)
self._remove_job()
self._reset_progress_data()
self._state_monitor.set_state(self._dict(text=self.get_state_string(), flags=self._get_state_flags()))
if event_type == "done" and self._on_streaming_done is not None:
self._on_streaming_done(job.name, job.name, FileDestinations.SDCARD)
eventManager().fire(Events.TRANSFER_DONE, {"local": job.name, "remote": job.remote})
elif event_type == "cancelled" and self._on_streaming_failed is not None:
self._on_streaming_failed(job.name, job.name, FileDestinations.SDCARD)
eventManager().fire(Events.TRANSFER_FAILED, {"local": job.name, "remote": job.remote})
return True
# ~~ octoprint.comm.job.PrintjobListener implementation
def on_job_progress(self, job):
+1 -1
View File
@@ -334,7 +334,7 @@ def uploadGcodeFile(target):
"""
if destination == FileDestinations.SDCARD and octoprint.filemanager.valid_file_type(filename, "machinecode"):
return filename, printer.add_sd_file(filename, absFilename, selectAndOrPrint, tags={"source:api", "api:files.sd"})
return filename, printer.add_sd_file(filename, absFilename, selectAndOrPrint, tags={"source:api", "api:files.sd"}, user=user)
else:
selectAndOrPrint(filename, absFilename, destination)
return filename