Add API function to (re)analyse files

This commit is contained in:
Gina Häußge 2017-07-05 16:37:03 +02:00
parent c81c93896b
commit cc3d34635e
4 changed files with 37 additions and 0 deletions

View file

@ -253,6 +253,26 @@ class FileManager(object):
def default_slicer(self):
return self._slicing_manager.default_slicer
def analyse(self, destination, path, printer_profile_id=None):
if not self.file_exists(destination, path):
return
if printer_profile_id is None:
printer_profile = self._printer_profile_manager.get_current_or_default()
else:
printer_profile = self._printer_profile_manager.get(printer_profile_id)
if printer_profile is None:
printer_profile = self._printer_profile_manager.get_current_or_default()
queue_entry = self._analysis_queue_entry(destination, path)
self._analysis_queue.dequeue(queue_entry)
queue_entry = self._analysis_queue_entry(destination, path, printer_profile=printer_profile)
if queue_entry:
return self._analysis_queue.enqueue(queue_entry, high_priority=True)
return False
def slice(self, slicer_name, source_location, source_path, dest_location, dest_path,
position=None, profile=None, printer_profile_id=None, overrides=None, callback=None, callback_args=None):
absolute_source_path = self.path_on_disk(source_location, source_path)

View file

@ -464,6 +464,7 @@ def gcodeFileCommand(filename, target):
valid_commands = {
"select": [],
"slice": [],
"analyse": [],
"copy": ["destination"],
"move": ["destination"]
}
@ -616,6 +617,17 @@ def gcodeFileCommand(filename, target):
r.headers["Location"] = location
return r
elif command == "analyse":
if not _verifyFileExists(target, filename):
return make_response("File not found on '%s': %s" % (target, filename), 404)
printer_profile = None
if "printerProfile" in data and data["printerProfile"]:
printer_profile = data["printerProfile"]
if not fileManager.analyse(target, filename, printer_profile_id=printer_profile):
return make_response("No analysis possible for {} on {}".format(filename, target), 400)
elif command == "copy" or command == "move":
# Copy and move are only possible on local storage
if not target in [FileDestinations.LOCAL]:

View file

@ -89,6 +89,10 @@
return this.issueEntryCommand(location, path, "select", data, opts);
};
OctoPrintFilesClient.prototype.analyse = function (location, path, parameters, opts) {
return this.issueEntryCommand(location, path, "analyse", parameters || {}, opts);
};
OctoPrintFilesClient.prototype.slice = function (location, path, parameters, opts) {
return this.issueEntryCommand(location, path, "slice",
parameters || {}, opts);

View file

@ -18,6 +18,7 @@
<div class="additionalInfo hide" data-bind="html: $root.getAdditionalData($data)"></div>
<div class="btn-group action-buttons">
<div class="btn btn-mini toggleAdditionalData" data-bind="click: function() { if ($root.enableAdditionalData($data)) { $root.toggleAdditionalData($data); } else { return; } }, css: { disabled: !$root.enableAdditionalData($data) }" title="{{ _('Additional data') }}"><i class="fa fa-chevron-down"></i></div>
<div class="btn btn-mini" data-bind="visible: $root.displayAnalyse, click: function() { if ($root.enableAnalyse($data)) { $root.analyseFile($data); } else { return; } }, css: {disabled: !$root.enableAnalyse($data)}" title="{{ _('(Re)Analyse') }}"><i class="fa fa-refresh"></i></div>
<a class="btn btn-mini" data-bind="attr: {href: $root.downloadLink($data)}, css: {disabled: !$root.downloadLink($data)}" title="{{ _('Download') }}"><i class="fa fa-download"></i></a>
<div class="btn btn-mini" data-bind="click: function(data, event) { if ($root.enableRemove($data)) { $root.removeFile($data, event); } else { return; } }, css: {disabled: !$root.enableRemove($data)}" title="{{ _('Remove') }}"><i class="fa fa-trash-o"></i></div>
<div class="btn btn-mini" data-bind="click: function() { if ($root.enableSelect($data)) { $root.loadFile($data, false); } else { return; } }, css: {disabled: !$root.enableSelect($data)}" title="{{ _('Load') }}"><i class="fa fa-folder-open"></i></div>