Only list those SD files that have a ASCII filename
According to the RepRap protocol we should actually not ever get anything other than those anyways, as the protocol is defined as ASCII-only. In the future there might be a way to somehow handle such files too, for the time being this fixes issues though where non-ascii files on the SD made the whole SD file handling not work. Closes #381
This commit is contained in:
parent
592f3dce9a
commit
b115b6f66c
2 changed files with 25 additions and 3 deletions
|
|
@ -191,6 +191,24 @@ def silentRemove(file):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def sanitizeAscii(line):
|
||||||
|
return unicode(line, 'ascii', 'replace').encode('ascii', 'replace').rstrip()
|
||||||
|
|
||||||
|
|
||||||
|
def filterNonAscii(line):
|
||||||
|
"""
|
||||||
|
Returns True if the line contains non-ascii characters, false otherwise
|
||||||
|
|
||||||
|
@param line the line to test
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
unicode(line, 'ascii').encode('ascii')
|
||||||
|
return False
|
||||||
|
except ValueError:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def getJsonCommandFromRequest(request, valid_commands):
|
def getJsonCommandFromRequest(request, valid_commands):
|
||||||
if not "application/json" in request.headers["Content-Type"]:
|
if not "application/json" in request.headers["Content-Type"]:
|
||||||
return None, None, make_response("Expected content-type JSON", 400)
|
return None, None, make_response("Expected content-type JSON", 400)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ from octoprint.settings import settings
|
||||||
from octoprint.events import eventManager, Events
|
from octoprint.events import eventManager, Events
|
||||||
from octoprint.filemanager.destinations import FileDestinations
|
from octoprint.filemanager.destinations import FileDestinations
|
||||||
from octoprint.gcodefiles import isGcodeFileName
|
from octoprint.gcodefiles import isGcodeFileName
|
||||||
from octoprint.util import getExceptionString, getNewTimeout
|
from octoprint.util import getExceptionString, getNewTimeout, sanitizeAscii, filterNonAscii
|
||||||
from octoprint.util.virtual import VirtualPrinter
|
from octoprint.util.virtual import VirtualPrinter
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -605,7 +605,11 @@ class MachineCom(object):
|
||||||
##~~ SD file list
|
##~~ 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 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 isGcodeFileName(line.strip().lower()) and not 'End file list' in line:
|
if self._sdFileList and isGcodeFileName(line.strip().lower()) and not 'End file list' in line:
|
||||||
self._sdFiles.append(line.strip().lower())
|
filename = line.strip().lower()
|
||||||
|
if filterNonAscii(filename):
|
||||||
|
self._logger.warn("Got a file from printer's SD that has a non-ascii filename (%s), that shouldn't happen according to the protocol" % filename)
|
||||||
|
else:
|
||||||
|
self._sdFiles.append(filename)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
##~~ Temperature processing
|
##~~ Temperature processing
|
||||||
|
|
@ -920,7 +924,7 @@ class MachineCom(object):
|
||||||
if ret == '':
|
if ret == '':
|
||||||
#self._log("Recv: TIMEOUT")
|
#self._log("Recv: TIMEOUT")
|
||||||
return ''
|
return ''
|
||||||
self._log("Recv: %s" % (unicode(ret, 'ascii', 'replace').encode('ascii', 'replace').rstrip()))
|
self._log("Recv: %s" % sanitizeAscii(ret))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _sendNext(self):
|
def _sendNext(self):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue