Also support extended sd file list (including size in bytes) from printer

See also #486 where support for SD_EXTENDED_DIR format was requested between the lines ;)
This commit is contained in:
Gina Häußge 2014-05-30 18:05:43 +02:00
parent 7414c921f3
commit ee31808522
4 changed files with 43 additions and 12 deletions

View file

@ -51,14 +51,17 @@ def _getFileList(origin):
files = []
if sdFileList is not None:
for sdFile in sdFileList:
files.append({
for sdFile, sdSize in sdFileList:
file = {
"name": sdFile,
"origin": FileDestinations.SDCARD,
"refs": {
"resource": url_for(".readGcodeFile", target=FileDestinations.SDCARD, filename=sdFile, _external=True)
}
})
}
if sdSize is not None:
file.update({"size": sdSize})
files.append(file)
else:
files = gcodeManager.getAllFileData()
for file in files:

View file

@ -147,7 +147,8 @@ default_settings = {
"numExtruders": 1,
"includeCurrentToolInTemps": True,
"hasBed": True,
"repetierStyleTargetTemperature": False
"repetierStyleTargetTemperature": False,
"extendedSdFileList": False
}
}
}

View file

@ -645,13 +645,28 @@ class MachineCom(object):
##~~ 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 isGcodeFileName(line.strip().lower()) and not 'End file list' in line:
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)
if self._sdFileList and not "End file list" in line:
fileinfo = line.strip().split(None, 2)
if len(fileinfo) > 1:
# we got extended file information here, so let's split filename and size and try to make them a bit nicer
filename, size = fileinfo
filename = filename.lower()
try:
size = int(size)
except ValueError:
# whatever that was, it was not an integer, so we'll just ignore it and set size to None
size = None
else:
self._sdFiles.append(filename)
continue
# no extended file information, so only the filename is there and we set size to None
filename = fileinfo[0].lower()
size = None
if isGcodeFileName(filename):
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, size))
continue
##~~ Temperature processing
if ' T:' in line or line.startswith('T:') or ' T0:' in line or line.startswith('T0:'):

View file

@ -155,8 +155,20 @@ class VirtualPrinter():
def _listSd(self):
self.readList.append("Begin file list")
for osFile in os.listdir(self._virtualSd):
self.readList.append(osFile.upper())
if settings().getBoolean(["devel", "virtualPrinter", "extendedSdFileList"]):
self.readList.extend(
map(
lambda x: "%s %d" % (x.upper(), os.stat(os.path.join(self._virtualSd, x)).st_size),
os.listdir(self._virtualSd)
)
)
else:
self.readList.extend(
map(
lambda x: x.upper(),
os.listdir(self._virtualSd)
)
)
self.readList.append("End file list")
self._sendOk()