file_manager: handle gcode files with special characters
Files with quotation marks and spaces are now acceptable and properly handled. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
8bb7139468
commit
2ddd1966fe
|
@ -373,8 +373,7 @@ class FileManager:
|
||||||
full_path = root_path
|
full_path = root_path
|
||||||
dir_path = ""
|
dir_path = ""
|
||||||
else:
|
else:
|
||||||
parts = os.path.split(upload['filename'].strip().lstrip("/"))
|
filename = upload['filename'].strip().lstrip("/")
|
||||||
filename = os.path.join(parts[0], "_".join(parts[1].split()))
|
|
||||||
if dir_path:
|
if dir_path:
|
||||||
filename = os.path.join(dir_path, filename)
|
filename = os.path.join(dir_path, filename)
|
||||||
full_path = os.path.normpath(os.path.join(root_path, filename))
|
full_path = os.path.normpath(os.path.join(root_path, filename))
|
||||||
|
@ -653,8 +652,11 @@ class MetadataStorage:
|
||||||
self.busy = False
|
self.busy = False
|
||||||
|
|
||||||
async def _run_extract_metadata(self, filename, notify):
|
async def _run_extract_metadata(self, filename, notify):
|
||||||
|
# Escape single quotes in the file name so that it may be
|
||||||
|
# properly loaded
|
||||||
|
filename = filename.replace("\"", "\\\"")
|
||||||
cmd = " ".join([sys.executable, METADATA_SCRIPT, "-p",
|
cmd = " ".join([sys.executable, METADATA_SCRIPT, "-p",
|
||||||
self.gc_path, "-f", "'" + filename + "'"])
|
self.gc_path, "-f", f"\"{filename}\""])
|
||||||
shell_command = self.server.lookup_plugin('shell_command')
|
shell_command = self.server.lookup_plugin('shell_command')
|
||||||
scmd = shell_command.build_shell_command(
|
scmd = shell_command.build_shell_command(
|
||||||
cmd, self._handle_script_response)
|
cmd, self._handle_script_response)
|
||||||
|
|
|
@ -80,6 +80,8 @@ class KlippyAPI:
|
||||||
# XXX - validate that file is on disk
|
# XXX - validate that file is on disk
|
||||||
if filename[0] == '/':
|
if filename[0] == '/':
|
||||||
filename = filename[1:]
|
filename = filename[1:]
|
||||||
|
# Escape existing double quotes in the file name
|
||||||
|
filename = filename.replace("\"", "\\\"")
|
||||||
script = f'SDCARD_PRINT_FILE FILENAME="{filename}"'
|
script = f'SDCARD_PRINT_FILE FILENAME="{filename}"'
|
||||||
return await self.run_gcode(script)
|
return await self.run_gcode(script)
|
||||||
|
|
||||||
|
|
|
@ -451,6 +451,8 @@ class PanelDue:
|
||||||
|
|
||||||
def _prepare_M32(self, args):
|
def _prepare_M32(self, args):
|
||||||
filename = self._clean_filename(args[0])
|
filename = self._clean_filename(args[0])
|
||||||
|
# Escape existing double quotes in the file name
|
||||||
|
filename = filename.replace("\"", "\\\"")
|
||||||
return f"SDCARD_PRINT_FILE FILENAME=\"{filename}\""
|
return f"SDCARD_PRINT_FILE FILENAME=\"{filename}\""
|
||||||
|
|
||||||
def _prepare_M98(self, args):
|
def _prepare_M98(self, args):
|
||||||
|
|
Loading…
Reference in New Issue