Merge branch 'maintenance' into devel

This commit is contained in:
Gina Häußge committed 2021-03-16 14:35:40 +01:00
commit 262983840a
5 files changed
+182 -137

No files matched your search

+6 -2
View File
@@ -14,7 +14,8 @@ Retrieve all files
.. http:get:: /api/files
Retrieve information regarding all files currently available and regarding the disk space still available
locally in the system.
locally in the system. The results are cached for performance reasons. If you
want to override the cache, supply the query parameter ``force`` and set it to ``true``.
By default only returns the files and folders in the root directory. If the query parameter ``recursive``
is provided and set to ``true``, returns all files and folders.
@@ -234,6 +235,7 @@ Retrieve all files
"free": "3.2GB"
}
:param force: If set to ``true``, forces a refresh, overriding the cache.
:param recursive: If set to ``true``, return all files and folders recursively. Otherwise only return items on same level.
:statuscode 200: No error
@@ -245,7 +247,8 @@ Retrieve files from specific location
.. http:get:: /api/files/(string:location)
Retrieve information regarding the files currently available on the selected `location` and -- if targeting
the ``local`` location -- regarding the disk space still available locally in the system.
the ``local`` location -- regarding the disk space still available locally in the system. The results are cached for performance reasons. If you
want to override the cache, supply the query parameter ``force`` and set it to ``true``.
By default only returns the files and folders in the root directory. If the query parameter ``recursive``
is provided and set to ``true``, returns all files and folders.
@@ -305,6 +308,7 @@ Retrieve files from specific location
:param location: The origin location from which to retrieve the files. Currently only ``local`` and ``sdcard`` are
supported, with ``local`` referring to files stored in OctoPrint's ``uploads`` folder and ``sdcard``
referring to files stored on the printer's SD card (if available).
:param force: If set to ``true``, forces a refresh, overriding the cache.
:param recursive: If set to ``true``, return all files and folders recursively. Otherwise only return items on same level.
:statuscode 200: No error
:statuscode 404: If `location` is neither ``local`` nor ``sdcard``
+21
View File
@@ -54,6 +54,27 @@ resumed
disconnect
When this command is received from the printer, OctoPrint will immediately disconnect from it.
sd_inserted
When this command is received from the printer, OctoPrint will assume an SD card is present in the printer,
set the corresponding internal state flags and send a file list request. This command is only recognized
if SD support is enabled in OctoPrint.
.. versionadded:: 1.6.0
sd_ejected
When this command is received from the printer, OctoPrint will assume the SD card has been removed from
the printer and clear the corresponding internal state flags. This command is only recognized
if SD support is enabled in OctoPrint.
.. versionadded:: 1.6.0
sd_updated
When this command is received from the printer, OctoPrint will assume something on the SD card in the
printer has changed and trigger a file list request. This command is only recognized
if SD support is enabled in OctoPrint.
.. versionadded:: 1.6.0
If the bundled :ref:`Action Command Prompt Support Plugin <sec-bundledplugins-action_command_prompt>` is enabled (which
should be the case by default), OctoPrint will also interactive dialog creation through its :ref:`supported commands <sec-bundledplugins-action_command_prompt-action_commands>`.
+11 -9
View File
@@ -897,16 +897,18 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
# ~~ sd file handling
def get_sd_files(self, *args, **kwargs):
if self._comm is None or not self._comm.isSdReady():
result = []
else:
result = list(
map(
lambda x: {"name": x[0][1:], "size": x[1], "display": x[2]},
self._comm.getSdFiles(),
)
if not self.is_sd_ready():
return []
if kwargs.get("refresh"):
self.refresh_sd_files(blocking=True)
return list(
map(
lambda x: {"name": x[0][1:], "size": x[1], "display": x[2]},
self._comm.getSdFiles(),
)
return result
)
def add_sd_file(
self, filename, path, on_success=None, on_failure=None, *args, **kwargs
+2 -2
View File
@@ -154,7 +154,7 @@ def readGcodeFiles():
recursive=recursive,
allow_from_cache=not force,
)
files.extend(_getFileList(FileDestinations.SDCARD))
files.extend(_getFileList(FileDestinations.SDCARD, allow_from_cache=not force))
usage = psutil.disk_usage(settings().getBaseFolder("uploads", check_writable=False))
return jsonify(files=files, free=usage.free, total=usage.total)
@@ -251,7 +251,7 @@ def _getFileList(
origin, path=None, filter=None, recursive=False, level=0, allow_from_cache=True
):
if origin == FileDestinations.SDCARD:
sdFileList = printer.get_sd_files()
sdFileList = printer.get_sd_files(refresh=not allow_from_cache)
files = []
if sdFileList is not None:
+142 -124
View File
@@ -2270,6 +2270,19 @@ class MachineCom:
elif action_name == "disconnect":
self._log("Disconnecting on request of the printer...")
self._callback.on_comm_force_disconnect()
elif self._sdEnabled and action_name == "sd_inserted":
self._log("Printer reported SD card as inserted")
self._sdAvailable = True
self.refreshSdFiles()
self._callback.on_comm_sd_state_change(self._sdAvailable)
elif self._sdEnabled and action_name == "sd_ejected":
self._log("Printer reported SD card as ejected")
self._sdAvailable = False
self._sdFiles = []
self._callback.on_comm_sd_state_change(self._sdAvailable)
elif self._sdEnabled and action_name == "sd_updated":
self._log("Printer reported a change on the SD card")
self.refreshSdFiles()
else:
for name, hook in self._printer_action_hooks.items():
try:
@@ -2308,7 +2321,7 @@ class MachineCom:
##~~ SD file list
# if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing
if self._sdFileList and "End file list" not in line:
if self._sdEnabled and self._sdFileList and "End file list" not in line:
preprocessed_line = line
fileinfo = preprocessed_line.split(None, 2)
if len(fileinfo) == 3:
@@ -2768,140 +2781,145 @@ class MachineCom:
)
##~~ SD Card handling
elif (
"SD init fail" in line
or "volume.init failed" in line
or "openRoot failed" in line
):
self._sdAvailable = False
self._sdFiles = []
self._callback.on_comm_sd_state_change(self._sdAvailable)
elif "SD card ok" in line and not self._sdAvailable:
self._sdAvailable = True
self.refreshSdFiles()
self._callback.on_comm_sd_state_change(self._sdAvailable)
elif "Begin file list" in line:
self._sdFiles = []
self._sdFileList = True
elif "End file list" in line:
self._sdFileList = False
self._callback.on_comm_sd_files(self.getSdFiles())
elif "SD printing byte" in line:
# answer to M27, at least on Marlin, Repetier and Sprinter: "SD printing byte %d/%d"
match = regex_sdPrintingByte.search(line)
if match:
try:
current = int(match.group("current"))
total = int(match.group("total"))
except Exception:
self._logger.exception("Error while parsing SD status report")
else:
if (
current == total == 0
and self.isSdPrinting()
and not self.isStarting()
and not self.isStarting()
and not self.isFinishing()
):
# apparently not SD printing - some Marlin versions report it like that for some reason
self._consecutive_not_sd_printing += 1
if (
self._consecutive_not_sd_printing
> self._consecutive_not_sd_printing_maximum
):
self.cancelPrint(external_sd=True)
else:
self._consecutive_not_sd_printing = 0
if self.isSdFileSelected():
# If we are not yet sd printing, the current does not equal the total, is larger
# than zero and has increased since the last time we saw a position report, then
# yes, this looks like we just started printing due to an external trigger.
if (
not self.isSdPrinting()
and current != total
and current > 0
and self._currentFile
and current > self._currentFile.pos
):
self.startPrint(external_sd=True)
self._currentFile.pos = current
if self._currentFile.size == 0:
self._currentFile.size = total
if not self._currentFile.done:
self._callback.on_comm_progress()
elif (
"Not SD printing" in line
and self.isSdPrinting()
and not self.isStarting()
and not self.isFinishing()
):
self._consecutive_not_sd_printing += 1
elif self._sdEnabled:
if (
self._consecutive_not_sd_printing
> self._consecutive_not_sd_printing_maximum
"SD init fail" in line
or "volume.init failed" in line
or "openRoot failed" in line
):
# something went wrong, printer is reporting that we actually are not printing right now...
self.cancelPrint(external_sd=True)
elif "File opened" in line and not self._ignore_select:
# answer to M23, at least on Marlin, Repetier and Sprinter: "File opened:%s Size:%d"
match = regex_sdFileOpened.search(line)
if match:
name = match.group("name")
size = int(match.group("size"))
else:
name = "Unknown"
size = 0
user = None
self._sdAvailable = False
self._sdFiles = []
self._callback.on_comm_sd_state_change(self._sdAvailable)
elif "SD card ok" in line and not self._sdAvailable:
self._sdAvailable = True
self.refreshSdFiles()
self._callback.on_comm_sd_state_change(self._sdAvailable)
elif "Begin file list" in line:
self._sdFiles = []
self._sdFileList = True
elif "End file list" in line:
self._sdFileList = False
self._callback.on_comm_sd_files(self.getSdFiles())
elif "SD printing byte" in line:
# answer to M27, at least on Marlin, Repetier and Sprinter: "SD printing byte %d/%d"
match = regex_sdPrintingByte.search(line)
if match:
try:
current = int(match.group("current"))
total = int(match.group("total"))
except Exception:
self._logger.exception(
"Error while parsing SD status report"
)
else:
if (
current == total == 0
and self.isSdPrinting()
and not self.isStarting()
and not self.isStarting()
and not self.isFinishing()
):
# apparently not SD printing - some Marlin versions report it like that for some reason
self._consecutive_not_sd_printing += 1
if (
self._consecutive_not_sd_printing
> self._consecutive_not_sd_printing_maximum
):
self.cancelPrint(external_sd=True)
if self._sdFileToSelect:
name = self._sdFileToSelect
user = self._sdFileToSelectUser
else:
self._consecutive_not_sd_printing = 0
if self.isSdFileSelected():
self._sdFileToSelect = None
self._sdFileToSelectUser = None
# If we are not yet sd printing, the current does not equal the total, is larger
# than zero and has increased since the last time we saw a position report, then
# yes, this looks like we just started printing due to an external trigger.
if (
not self.isSdPrinting()
and current != total
and current > 0
and self._currentFile
and current > self._currentFile.pos
):
self.startPrint(external_sd=True)
self._currentFile = PrintingSdFileInformation(name, size, user=user)
elif "File selected" in line:
if self._ignore_select:
self._ignore_select = False
elif self._currentFile is not None and self.isSdFileSelected():
# final answer to M23, at least on Marlin, Repetier and Sprinter: "File selected"
self._callback.on_comm_file_selected(
self._currentFile.getFilename(),
self._currentFile.getFilesize(),
True,
user=self._currentFile.getUser(),
self._currentFile.pos = current
if self._currentFile.size == 0:
self._currentFile.size = total
if not self._currentFile.done:
self._callback.on_comm_progress()
elif (
"Not SD printing" in line
and self.isSdPrinting()
and not self.isStarting()
and not self.isFinishing()
):
self._consecutive_not_sd_printing += 1
if (
self._consecutive_not_sd_printing
> self._consecutive_not_sd_printing_maximum
):
# something went wrong, printer is reporting that we actually are not printing right now...
self.cancelPrint(external_sd=True)
elif "File opened" in line and not self._ignore_select:
# answer to M23, at least on Marlin, Repetier and Sprinter: "File opened:%s Size:%d"
match = regex_sdFileOpened.search(line)
if match:
name = match.group("name")
size = int(match.group("size"))
else:
name = "Unknown"
size = 0
user = None
if self._sdFileToSelect:
name = self._sdFileToSelect
user = self._sdFileToSelectUser
self._sdFileToSelect = None
self._sdFileToSelectUser = None
self._currentFile = PrintingSdFileInformation(
name, size, user=user
)
elif "Writing to file" in line and self.isStreaming():
self._changeState(self.STATE_PRINTING)
elif "Done printing file" in line and self.isSdPrinting():
# printer is reporting file finished printing
self._changeState(self.STATE_FINISHING)
elif "File selected" in line:
if self._ignore_select:
self._ignore_select = False
elif self._currentFile is not None and self.isSdFileSelected():
# final answer to M23, at least on Marlin, Repetier and Sprinter: "File selected"
self._callback.on_comm_file_selected(
self._currentFile.getFilename(),
self._currentFile.getFilesize(),
True,
user=self._currentFile.getUser(),
)
elif "Writing to file" in line and self.isStreaming():
self._changeState(self.STATE_PRINTING)
elif "Done printing file" in line and self.isSdPrinting():
# printer is reporting file finished printing
self._changeState(self.STATE_FINISHING)
self._currentFile.done = True
self._currentFile.pos = 0
self._currentFile.done = True
self._currentFile.pos = 0
self.sendCommand("M400", part_of_job=True)
self._callback.on_comm_print_job_done()
self.sendCommand("M400", part_of_job=True)
self._callback.on_comm_print_job_done()
def finalize():
self._changeState(self.STATE_OPERATIONAL)
def finalize():
self._changeState(self.STATE_OPERATIONAL)
self.sendCommand(SendQueueMarker(finalize), part_of_job=True)
self._continue_sending()
elif "Done saving file" in line:
if self._trigger_ok_for_m29:
# workaround for most versions of Marlin out in the wild
# not sending an ok after saving a file
self.sendCommand(SendQueueMarker(finalize), part_of_job=True)
self._continue_sending()
elif "Done saving file" in line:
if self._trigger_ok_for_m29:
# workaround for most versions of Marlin out in the wild
# not sending an ok after saving a file
self._handle_ok()
elif "File deleted" in line and line.strip().endswith("ok"):
# buggy Marlin version that doesn't send a proper line break after the "File deleted" statement, fixed in
# current versions
self._handle_ok()
elif "File deleted" in line and line.strip().endswith("ok"):
# buggy Marlin version that doesn't send a proper line break after the "File deleted" statement, fixed in
# current versions
self._handle_ok()
##~~ Message handling
self._callback.on_comm_message(line)