Merge branch 'pr/2576' into maintenance

# Conflicts:
#	src/octoprint/printer/standard.py
This commit is contained in:
Gina Häußge committed 2018-04-24 16:45:08 +02:00
commit b653ee59c8
7 files changed
+85 -40

No files matched your search

+1
View File
@@ -89,6 +89,7 @@ date of first contribution):
* [Bernd Zeimetz](https://github.com/bzed)
* [Daniele Forsi](https://github.com/dforsi)
* [Ganey](https://github.com/ganey)
* [Sven Lohrmann](https://github.com/malnvenshorn)
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
[Daid Braam](https://github.com/daid). Parts of its communication layer and
+26 -14
View File
@@ -113,7 +113,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
estimatedPrintTime=None,
lastPrintTime=None,
filament=self._dict(length=None,
volume=None)),
volume=None),
user=None),
progress=self._dict(completion=None,
filepos=None,
printTime=None,
@@ -174,14 +175,16 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
if self._selectedFile:
self._setJobData(self._selectedFile["filename"],
self._selectedFile["filesize"],
self._selectedFile["sd"])
self._selectedFile["sd"],
self._selectedFile["user"])
def _on_event_MetadataStatisticsUpdated(self, event, data):
with self._selectedFileMutex:
if self._selectedFile:
self._setJobData(self._selectedFile["filename"],
self._selectedFile["filesize"],
self._selectedFile["sd"])
self._selectedFile["sd"],
self._selectedFile["user"])
#~~ progress plugin reporting
@@ -418,7 +421,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
self.commands("M221 S%d" % factor,
tags=kwargs.get("tags", set()) | {"trigger:printer.flow_rate"})
def select_file(self, path, sd, printAfterSelect=False, pos=None, *args, **kwargs):
def select_file(self, path, sd, printAfterSelect=False, user=None, pos=None, *args, **kwargs):
if self._comm is None or (self._comm.isBusy() or self._comm.isStreaming()):
self._logger.info("Cannot load file: printer not connected or currently busy")
return
@@ -441,6 +444,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
self._printAfterSelect = printAfterSelect
self._posAfterSelect = pos
self._comm.selectFile("/" + path if sd else path_on_disk, sd,
user=user,
tags=kwargs.get("tags", set()) | {"trigger:printer.select_file"})
self._updateProgressData()
self._setCurrentZ(None)
@@ -463,7 +467,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
return self._comm.getFilePosition()
def start_print(self, pos=None, *args, **kwargs):
def start_print(self, pos=None, user=None, *args, **kwargs):
"""
Starts the currently loaded print job.
Only starts if the printer is connected and operational, not currently printing and a printjob is loaded
@@ -496,6 +500,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
self._lastProgressReport = None
self._updateProgressData()
self._setCurrentZ(None)
self._setPrintingUser(user)
self._comm.startPrint(pos=pos,
tags=kwargs.get("tags", set()) | {"trigger:printer.start_print"})
@@ -926,7 +931,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
if not os.path.isfile(path_on_disk):
raise InvalidFileLocation("{} does not exist in local storage, cannot select for printing".format(filename))
def _setJobData(self, filename, filesize, sd):
def _setJobData(self, filename, filesize, sd, user=None):
with self._selectedFileMutex:
if filename is not None:
if sd:
@@ -943,7 +948,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
"filename": path_in_storage,
"filesize": filesize,
"sd": sd,
"estimatedPrintTime": None
"estimatedPrintTime": None,
"user": user
}
else:
self._selectedFile = None
@@ -956,7 +962,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
estimatedPrintTime=None,
averagePrintTime=None,
lastPrintTime=None,
filament=None))
filament=None,
user=None))
return
estimatedPrintTime = None
@@ -1007,7 +1014,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
estimatedPrintTime=estimatedPrintTime,
averagePrintTime=averagePrintTime,
lastPrintTime=lastPrintTime,
filament=filament))
filament=filament,
user=user))
def _sendInitialStateUpdate(self, callback):
try:
@@ -1131,7 +1139,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
eventManager().fire(Events.UPDATED_FILES, {"type": "gcode"})
self._sdFilelistAvailable.set()
def on_comm_file_selected(self, full_path, size, sd):
def on_comm_file_selected(self, full_path, size, sd, user=None):
if full_path is not None:
payload = self._payload_for_print_job_event(location=FileDestinations.SDCARD if sd else FileDestinations.LOCAL,
print_job_file=full_path)
@@ -1139,12 +1147,12 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
else:
eventManager().fire(Events.FILE_DESELECTED)
self._setJobData(full_path, size, sd)
self._setJobData(full_path, size, sd, user=user)
self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags()))
if self._printAfterSelect:
self._printAfterSelect = False
self.start_print(pos=self._posAfterSelect)
self.start_print(pos=self._posAfterSelect, user=self._printingUser)
def on_comm_print_job_started(self):
payload = self._payload_for_print_job_event()
@@ -1156,6 +1164,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
def on_comm_print_job_done(self):
self._fileManager.delete_recovery_data()
self._setPrintingUser(None)
payload = self._payload_for_print_job_event()
if payload:
@@ -1189,6 +1198,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
def on_comm_print_job_failed(self):
self._setPrintingUser(None)
payload = self._payload_for_print_job_event()
if payload:
eventManager().fire(Events.PRINT_FAILED, payload)
@@ -1203,6 +1214,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
def on_comm_print_job_cancelled(self):
self._setCurrentZ(None)
self._updateProgressData()
self._setPrintingUser(None)
payload = self._payload_for_print_job_event(position=self._comm.cancel_position.as_dict() if self._comm and self._comm.cancel_position else None)
if payload:
@@ -1242,10 +1254,10 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
context=dict(event=payload),
must_be_set=False)
def on_comm_file_transfer_started(self, filename, filesize):
def on_comm_file_transfer_started(self, filename, filesize, user=None):
self._sdStreaming = True
self._setJobData(filename, filesize, True)
self._setJobData(filename, filesize, True, user=user)
self._updateProgressData(completion=0.0, filepos=0, printTime=0)
self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags()))
+8 -4
View File
@@ -9,7 +9,7 @@ from flask import request, jsonify, make_response, url_for
from octoprint.filemanager.destinations import FileDestinations
from octoprint.settings import settings, valid_boolean_trues
from octoprint.server import printer, fileManager, slicingManager, eventManager, NO_CONTENT
from octoprint.server import printer, fileManager, slicingManager, eventManager, NO_CONTENT, current_user
from octoprint.server.util.flask import restricted_access, get_json_command_from_request, with_revalidation_checking
from octoprint.server.api import api
from octoprint.events import Events
@@ -316,6 +316,8 @@ def uploadGcodeFile(target):
reselect = printer.is_current_file(futureFullPathInStorage, sd)
user = current_user.get_name()
def fileProcessingFinished(filename, absFilename, destination):
"""
Callback for when the file processing (upload, optional slicing, addition to analysis queue) has
@@ -340,7 +342,7 @@ def uploadGcodeFile(target):
exact file is already selected, such reloading it.
"""
if octoprint.filemanager.valid_file_type(added_file, "gcode") and (selectAfterUpload or printAfterSelect or reselect):
printer.select_file(absFilename, destination == FileDestinations.SDCARD, printAfterSelect)
printer.select_file(absFilename, destination == FileDestinations.SDCARD, printAfterSelect, user)
try:
added_file = fileManager.add_file(FileDestinations.LOCAL, futureFullPathInStorage, upload,
@@ -485,6 +487,8 @@ def gcodeFileCommand(filename, target):
if response is not None:
return response
user = current_user.get_name()
if command == "select":
if not _verifyFileExists(target, filename):
return make_response("File not found on '%s': %s" % (target, filename), 404)
@@ -505,7 +509,7 @@ def gcodeFileCommand(filename, target):
sd = True
else:
filenameToSelect = fileManager.path_on_disk(target, filename)
printer.select_file(filenameToSelect, sd, printAfterLoading)
printer.select_file(filenameToSelect, sd, printAfterLoading, user)
elif command == "slice":
if not _verifyFileExists(target, filename):
@@ -608,7 +612,7 @@ def gcodeFileCommand(filename, target):
sd = True
else:
filenameToSelect = fileManager.path_on_disk(target, path)
printer.select_file(filenameToSelect, sd, print_after_slicing)
printer.select_file(filenameToSelect, sd, print_after_slicing, user)
try:
fileManager.slice(slicer, target, filename, target, full_path,
+7 -4
View File
@@ -7,7 +7,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
from flask import request, make_response, jsonify
from octoprint.server import printer, NO_CONTENT
from octoprint.server import printer, NO_CONTENT, current_user
from octoprint.server.util.flask import restricted_access, get_json_command_from_request
from octoprint.server.api import api
import octoprint.util as util
@@ -34,14 +34,16 @@ def controlJob():
tags = {"source:api", "api:job"}
user = current_user.get_name()
if command == "start":
if activePrintjob:
return make_response("Printer already has an active print job, did you mean 'restart'?", 409)
printer.start_print(tags=tags)
printer.start_print(tags=tags, user=user)
elif command == "restart":
if not printer.is_paused():
return make_response("Printer does not have an active print job or is not paused", 409)
printer.start_print(tags=tags)
printer.start_print(tags=tags, user=user)
elif command == "pause":
if not activePrintjob:
return make_response("Printer is neither printing nor paused, 'pause' command cannot be performed", 409)
@@ -67,5 +69,6 @@ def jobState():
return jsonify({
"job": currentData["job"],
"progress": currentData["progress"],
"state": currentData["state"]["text"]
"state": currentData["state"]["text"],
"printingUser": currentData["printingUser"],
})
@@ -38,6 +38,7 @@ $(function() {
self.printTimeLeftOrigin = ko.observable(undefined);
self.sd = ko.observable(undefined);
self.timelapse = ko.observable(undefined);
self.user = ko.observable(undefined);
self.busyFiles = ko.observableArray([]);
@@ -167,6 +168,11 @@ $(function() {
}
});
self.userString = ko.pureComputed(function() {
var user = self.user();
return user ? user : "-";
});
self.fromCurrentData = function(data) {
self._fromData(data);
};
@@ -244,6 +250,8 @@ $(function() {
});
}
self.filament(result);
self.user(data.user);
};
self._processProgressData = function(data) {
@@ -1,6 +1,7 @@
<span title="{{ _('Current printer state') }}">{{ _('State') }}</span>: <strong data-bind="text: stateString"></strong><br>
<hr>
<span title="{{ _('Name of file currently selected for printing') }}">{{ _('File') }}</span>: <strong data-bind="text: filedisplay, attr: {title: filepath}"></strong>&nbsp;<strong data-bind="visible: sd">(SD)</strong><br>
<span title="{{ _('User who selected this file for printing') }}">{{ _('User') }}</span>: <strong data-bind="text: userString"></strong><br>
<span title="{{ _('Current timelapse configuration') }}">{{ _('Timelapse') }}</span>: <strong data-bind="text: timelapseString"></strong><br>
<!-- ko foreach: filament -->
<span data-bind="text: 'Filament (' + name() + '): ', title: 'Filament usage for ' + name()"></span><strong data-bind="text: formatFilament(data())"></strong><br>
+34 -18
View File
@@ -500,6 +500,7 @@ class MachineCom(object):
self._sdFileList = False
self._sdFiles = []
self._sdFileToSelect = None
self._sdFileToSelectUser = None
self._ignore_select = False
self._manualStreaming = False
@@ -1027,7 +1028,7 @@ class MachineCom(object):
self.sendCommand("M28 %s" % remoteFilename, tags=tags | {"trigger:comm.start_file_transfer",})
eventManager().fire(Events.TRANSFER_STARTED, {"local": localFilename, "remote": remoteFilename})
self._callback.on_comm_file_transfer_started(remoteFilename, self._currentFile.getFilesize())
self._callback.on_comm_file_transfer_started(remoteFilename, self._currentFile.getFilesize(), user=self._currentFile.getUser())
def cancelFileTransfer(self, tags=None):
if not self.isOperational() or not self.isStreaming():
@@ -1067,7 +1068,7 @@ class MachineCom(object):
self.refreshSdFiles(tags={"trigger:comm.finish_file_transfer",})
self._sendCommand(SendQueueMarker(finalize))
def selectFile(self, filename, sd, tags=None):
def selectFile(self, filename, sd, user=None, tags=None):
if self.isBusy():
return
@@ -1083,17 +1084,21 @@ class MachineCom(object):
filename = filename[1:]
self._sdFileToSelect = filename
self._sdFileToSelectUser = user
self.sendCommand("M23 %s" % filename, tags=tags | {"trigger:comm.select_file",})
else:
self._currentFile = PrintingGcodeFileInformation(filename, offsets_callback=self.getOffsets, current_tool_callback=self.getCurrentTool)
self._callback.on_comm_file_selected(filename, self._currentFile.getFilesize(), False)
self._currentFile = PrintingGcodeFileInformation(filename,
offsets_callback=self.getOffsets,
current_tool_callback=self.getCurrentTool,
user=user)
self._callback.on_comm_file_selected(filename, self._currentFile.getFilesize(), False, user=user)
def unselectFile(self):
if self.isBusy():
return
self._currentFile = None
self._callback.on_comm_file_selected(None, None, False)
self._callback.on_comm_file_selected(None, None, False, user=None)
def _cancel_preparation_failed(self):
timeout = self._timeout_intervals.get("positionLogWait", 10.0)
@@ -1822,14 +1827,18 @@ class MachineCom(object):
else:
name = "Unknown"
size = 0
user = None
expected = False
if self._sdFileToSelect:
expected = True
name = self._sdFileToSelect
self._sdFileToSelect = None
user = self._sdFileToSelectUser
self._currentFile = PrintingSdFileInformation(name, size)
self._sdFileToSelect = None
self._sdFileToSelectUser = None
self._currentFile = PrintingSdFileInformation(name, size, user=user)
if not expected:
# It doesn't look like we expected this, so it might be that someone just started a print
@@ -1841,7 +1850,10 @@ class MachineCom(object):
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)
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():
@@ -3393,7 +3405,7 @@ class MachineComPrintCallback(object):
def on_comm_z_change(self, newZ):
pass
def on_comm_file_selected(self, filename, filesize, sd):
def on_comm_file_selected(self, filename, filesize, sd, user=None):
pass
def on_comm_sd_state_change(self, sdReady):
@@ -3402,7 +3414,7 @@ class MachineComPrintCallback(object):
def on_comm_sd_files(self, files):
pass
def on_comm_file_transfer_started(self, filename, filesize):
def on_comm_file_transfer_started(self, filename, filesize, user=None):
pass
def on_comm_file_transfer_done(self, filename):
@@ -3429,9 +3441,10 @@ class PrintingFileInformation(object):
checksum = True
def __init__(self, filename):
def __init__(self, filename, user=None):
self._logger = logging.getLogger(__name__)
self._filename = filename
self._user = user
self._pos = 0
self._size = None
self._start_time = None
@@ -3452,6 +3465,9 @@ class PrintingFileInformation(object):
def getFileLocation(self):
return FileDestinations.LOCAL
def getUser(self):
return self._user
def getProgress(self):
"""
The current progress of the file, calculated as relation between file position and absolute size. Returns -1
@@ -3491,8 +3507,8 @@ class PrintingSdFileInformation(PrintingFileInformation):
checksum = False
def __init__(self, filename, size):
PrintingFileInformation.__init__(self, filename)
def __init__(self, filename, size, user=None):
PrintingFileInformation.__init__(self, filename, user=user)
self._size = size
def getFileLocation(self):
@@ -3528,8 +3544,8 @@ class PrintingGcodeFileInformation(PrintingFileInformation):
that the file is closed in case of an error.
"""
def __init__(self, filename, offsets_callback=None, current_tool_callback=None):
PrintingFileInformation.__init__(self, filename)
def __init__(self, filename, offsets_callback=None, current_tool_callback=None, user=None):
PrintingFileInformation.__init__(self, filename, user=user)
self._handle = None
self._handle_mutex = threading.RLock()
@@ -3630,8 +3646,8 @@ class PrintingGcodeFileInformation(PrintingFileInformation):
pass
class StreamingGcodeFileInformation(PrintingGcodeFileInformation):
def __init__(self, path, localFilename, remoteFilename):
PrintingGcodeFileInformation.__init__(self, path)
def __init__(self, path, localFilename, remoteFilename, user=None):
PrintingGcodeFileInformation.__init__(self, path, user=user)
self._localFilename = localFilename
self._remoteFilename = remoteFilename
@@ -4436,7 +4452,7 @@ def upload_cli():
self._target = target
self._state = None
def on_comm_file_transfer_started(self, filename, filesize):
def on_comm_file_transfer_started(self, filename, filesize, user=None):
# transfer started, report
logger.info("Started file transfer of {}, size {}B".format(filename, filesize))
self.started = True