Moved filetype decision stuff into gcodefiles module
This commit is contained in:
parent
00501f0913
commit
8ff48ed88d
6 changed files with 50 additions and 55 deletions
|
|
@ -17,7 +17,45 @@ from octoprint.events import eventManager
|
|||
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
SUPPORTED_EXTENSIONS=["gcode", "gco", "stl", "g"]
|
||||
GCODE_EXTENSIONS = ["gcode", "gco", "g"]
|
||||
STL_EXTENSIONS = ["stl"]
|
||||
SUPPORTED_EXTENSIONS = GCODE_EXTENSIONS + STL_EXTENSIONS
|
||||
|
||||
def isGcodeFileName(filename):
|
||||
"""Simple helper to determine if a filename has the .gcode extension.
|
||||
|
||||
:param filename: :class: `str`
|
||||
|
||||
:returns boolean:
|
||||
"""
|
||||
return "." in filename and filename.rsplit(".", 1)[1].lower() in GCODE_EXTENSIONS
|
||||
|
||||
|
||||
def isSTLFileName(filename):
|
||||
"""Simple helper to determine if a filename has the .stl extension.
|
||||
|
||||
:param filename: :class: `str`
|
||||
|
||||
:returns boolean:
|
||||
"""
|
||||
return "." in filename and filename.rsplit(".", 1)[1].lower() in STL_EXTENSIONS
|
||||
|
||||
|
||||
def genGcodeFileName(filename):
|
||||
if not filename:
|
||||
return None
|
||||
|
||||
name, ext = filename.rsplit(".", 1)
|
||||
return name + ".gcode"
|
||||
|
||||
|
||||
def genStlFileName(filename):
|
||||
if not filename:
|
||||
return None
|
||||
|
||||
name, ext = filename.rsplit(".", 1)
|
||||
return name + ".stl"
|
||||
|
||||
|
||||
class GcodeManager:
|
||||
def __init__(self):
|
||||
|
|
@ -122,8 +160,6 @@ class GcodeManager:
|
|||
#~~ file handling
|
||||
|
||||
def addFile(self, file, destination):
|
||||
from octoprint.util import isSTLFileName
|
||||
from octoprint.util import isGcodeFileName
|
||||
from octoprint.filemanager.destinations import FileDestinations
|
||||
|
||||
if not file or not destination:
|
||||
|
|
@ -164,7 +200,7 @@ class GcodeManager:
|
|||
from octoprint.slicers.cura import CuraFactory
|
||||
|
||||
cura = CuraFactory.create_slicer()
|
||||
gcodePath = util.genGcodeFileName(absolutePath)
|
||||
gcodePath = genGcodeFileName(absolutePath)
|
||||
config = self._settings.get(["cura", "config"])
|
||||
|
||||
slicingStart = time.time()
|
||||
|
|
@ -211,7 +247,7 @@ class GcodeManager:
|
|||
def removeFile(self, filename):
|
||||
filename = self._getBasicFilename(filename)
|
||||
absolutePath = self.getAbsolutePath(filename)
|
||||
stlPath = util.genStlFileName(absolutePath)
|
||||
stlPath = genStlFileName(absolutePath)
|
||||
|
||||
if absolutePath is None:
|
||||
return
|
||||
|
|
@ -260,8 +296,6 @@ class GcodeManager:
|
|||
return files
|
||||
|
||||
def getFileData(self, filename):
|
||||
from octoprint.util import isSTLFileName
|
||||
|
||||
if not filename:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -474,8 +474,8 @@ class Printer():
|
|||
return self._comm.getSdFiles()
|
||||
|
||||
def addSdFile(self, filename, absolutePath):
|
||||
from octoprint.util import isGcodeFileName
|
||||
from octoprint.util import isSTLFileName
|
||||
from octoprint.gcodefiles import isGcodeFileName
|
||||
from octoprint.gcodefiles import isSTLFileName
|
||||
|
||||
if not self._comm or self._comm.isBusy() or not self._comm.isSdReady():
|
||||
logging.error("No connection to printer or printer is busy")
|
||||
|
|
|
|||
|
|
@ -406,7 +406,7 @@ def uploadGcodeFile():
|
|||
currentSd = currentJob["sd"]
|
||||
|
||||
futureFilename = gcodeManager.getFutureFilename(file)
|
||||
if futureFilename is None or (not settings().getBoolean(["cura", "enabled"]) and not util.isGcodeFileName(futureFilename)):
|
||||
if futureFilename is None or (not settings().getBoolean(["cura", "enabled"]) and not gcodefiles.isGcodeFileName(futureFilename)):
|
||||
return make_response("Can not upload file %s, wrong format?" % file.filename, 400)
|
||||
|
||||
if futureFilename == currentFilename and sd == currentSd and printer.isPrinting() or printer.isPaused():
|
||||
|
|
@ -502,7 +502,7 @@ def apiLoad():
|
|||
|
||||
# Perform an upload
|
||||
file = request.files["file"]
|
||||
if not util.isGcodeFileName(file.filename):
|
||||
if not gcodefiles.isGcodeFileName(file.filename):
|
||||
abort(400)
|
||||
|
||||
filename, done = gcodeManager.addFile(file)
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class FileUtilTestCase(unittest.TestCase):
|
|||
|
||||
def test_isGcode(self):
|
||||
|
||||
from octoprint.util import isGcodeFileName
|
||||
from octoprint.gcodefiles import isGcodeFileName
|
||||
|
||||
filename = "/asdj/wefasdf/junk.stl"
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ class FileUtilTestCase(unittest.TestCase):
|
|||
|
||||
def test_isSTLFileName(self):
|
||||
|
||||
from octoprint.util import isSTLFileName
|
||||
from octoprint.gcodefiles import isSTLFileName
|
||||
filename = "/asdj/wefasdf/junk.stl"
|
||||
|
||||
result = isSTLFileName(filename)
|
||||
|
|
@ -113,7 +113,7 @@ class FileUtilTestCase(unittest.TestCase):
|
|||
|
||||
def test_genGcodeFileName(self):
|
||||
|
||||
from octoprint.util import genGcodeFileName
|
||||
from octoprint.gcodefiles import genGcodeFileName
|
||||
|
||||
filename = "test.stl"
|
||||
|
||||
|
|
|
|||
|
|
@ -54,46 +54,6 @@ def getClass(name):
|
|||
return m
|
||||
|
||||
|
||||
def isGcodeFileName(filename):
|
||||
"""Simple helper to determine if a filename has the .gcode extension.
|
||||
|
||||
:param filename: :class: `str`
|
||||
|
||||
:returns boolean:
|
||||
"""
|
||||
return "." in filename and filename.rsplit(".", 1)[1].lower() in ["gcode", "gco"]
|
||||
|
||||
|
||||
def isSTLFileName(filename):
|
||||
"""Simple helper to determine if a filename has the .stl extension.
|
||||
|
||||
:param filename: :class: `str`
|
||||
|
||||
:returns boolean:
|
||||
"""
|
||||
return "." in filename and filename.rsplit(".", 1)[1].lower() in ["stl"]
|
||||
|
||||
|
||||
def genGcodeFileName(filename):
|
||||
if not filename:
|
||||
return None
|
||||
|
||||
if "." not in filename:
|
||||
return filename + ".gcode"
|
||||
|
||||
return filename.replace('.stl', '.gcode')
|
||||
|
||||
|
||||
def genStlFileName(filename):
|
||||
if not filename:
|
||||
return None
|
||||
|
||||
if "." not in filename:
|
||||
return filename + ".stl"
|
||||
|
||||
return filename.replace('.gcode', '.stl')
|
||||
|
||||
|
||||
def isDevVersion():
|
||||
gitPath = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "../../.git"))
|
||||
return os.path.exists(gitPath)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from octoprint.util.avr_isp import ispBase
|
|||
|
||||
from octoprint.settings import settings
|
||||
from octoprint.events import eventManager
|
||||
from octoprint.gcodefiles import isGcodeFileName
|
||||
from octoprint.util import getExceptionString, getNewTimeout
|
||||
from octoprint.util.virtual import VirtualPrinter
|
||||
|
||||
|
|
@ -549,7 +550,7 @@ 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 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())
|
||||
continue
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue