From 26f7d6e5174a4dcf4387b47d7464dc0b55babef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 23 Feb 2014 11:07:09 +0100 Subject: [PATCH] Added logging and filtering of non-ASCII filenames of files returned from SD card, still WIP --- src/octoprint/comm/protocol/__init__.py | 10 ++++++---- src/octoprint/comm/protocol/reprap/__init__.py | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/octoprint/comm/protocol/__init__.py b/src/octoprint/comm/protocol/__init__.py index f7dc4f789..fca2c3bf6 100644 --- a/src/octoprint/comm/protocol/__init__.py +++ b/src/octoprint/comm/protocol/__init__.py @@ -1,13 +1,13 @@ # coding=utf-8 -import os -import time -from octoprint.events import eventManager, Events - __author__ = "Gina Häußge " __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" __copyright__ = "Copyright (C) 2014 Gina Häußge - Released under terms of the AGPLv3 License" +import logging +import os +import time +from octoprint.events import eventManager, Events from octoprint.comm.transport import MessageReceiver, StateReceiver, LogReceiver, State as TransportState from octoprint.filemanager.destinations import FileDestinations @@ -15,6 +15,8 @@ from octoprint.filemanager.destinations import FileDestinations class Protocol(MessageReceiver, StateReceiver, LogReceiver): def __init__(self, transportFactory, protocolListener=None): + self._logger = logging.getLogger(__name__) + self._transport = transportFactory(self, self, self) self._transportProperties = self._transport.getProperties() diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index 2a7daf859..0deefb425 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -2,6 +2,7 @@ import Queue from collections import deque from octoprint.events import eventManager, Events +from octoprint.util import filterNonAscii __author__ = "Gina Häußge " __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" @@ -158,7 +159,11 @@ class RepRapProtocol(Protocol): # SD file list if self._receivingSdFileList and isGcodeFileName(message.strip().lower()) and not RepRapProtocol.MESSAGE_SD_END_FILE_LIST(message): - self._addSdFile(message.strip().lower()) + filename = message.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._addSdFile(filename) return ##~~ regular message processing @@ -379,7 +384,7 @@ class RepRapProtocol(Protocol): pass if self._resendDelta > len(self._lastLines) or len(self._lastLines) == 0 or self._resendDelta <= 0: error = "Printer requested line %d but no sufficient history is available, can't resend" % lineToResend - # TODO self._logger.warn(error) + self._logger.warn(error) if self._isPrinting(): # abort the print, there's nothing we can do to rescue it now self.onError(error)