file_manager: Allow the self.file_paths to contain paths to files
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
f0fa1295a7
commit
bf1a666e20
|
@ -250,10 +250,15 @@ class FileManager:
|
||||||
|
|
||||||
def _update_file_list(self, base='gcodes'):
|
def _update_file_list(self, base='gcodes'):
|
||||||
# Use os.walk find files in sd path and subdirs
|
# Use os.walk find files in sd path and subdirs
|
||||||
path = self.file_paths.get(base, "")
|
path = self.file_paths.get(base, None)
|
||||||
if path is None:
|
if path is None:
|
||||||
logging.info("No sd_path set, cannot update")
|
msg = "No known path for root: %s" % (base)
|
||||||
return
|
logging.info(msg)
|
||||||
|
raise self.server.error(msg)
|
||||||
|
elif not os.path.isdir(path):
|
||||||
|
msg = "Cannot generate file list for root: %s" % (base)
|
||||||
|
logging.info(msg)
|
||||||
|
raise self.server.error(msg)
|
||||||
logging.info("Updating File List...")
|
logging.info("Updating File List...")
|
||||||
new_list = {}
|
new_list = {}
|
||||||
for root, dirs, files in os.walk(path, followlinks=True):
|
for root, dirs, files in os.walk(path, followlinks=True):
|
||||||
|
@ -299,10 +304,17 @@ class FileManager:
|
||||||
raise self.server.error(
|
raise self.server.error(
|
||||||
400, "Bad Request, can only process a single file upload")
|
400, "Bad Request, can only process a single file upload")
|
||||||
upload = f_list[0]
|
upload = f_list[0]
|
||||||
filename = "_".join(upload['filename'].strip().split()).lstrip("/")
|
if os.path.isfile(file_path):
|
||||||
if dir_path:
|
# If the root path points to a file, write directly to it. This
|
||||||
filename = os.path.join(dir_path, filename)
|
# is the case for printer.cfg
|
||||||
full_path = os.path.join(file_path, filename)
|
filename = root
|
||||||
|
full_path = file_path
|
||||||
|
dir_path = ""
|
||||||
|
else:
|
||||||
|
filename = "_".join(upload['filename'].strip().split()).lstrip("/")
|
||||||
|
if dir_path:
|
||||||
|
filename = os.path.join(dir_path, filename)
|
||||||
|
full_path = os.path.join(file_path, filename)
|
||||||
# Verify that the operation can be done if attempting to upload a gcode
|
# Verify that the operation can be done if attempting to upload a gcode
|
||||||
if root == 'gcodes':
|
if root == 'gcodes':
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue