From 4e60c9ff497c7c9882cad5f2faf1ee1e620f4cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 21 Jun 2016 17:34:30 +0200 Subject: [PATCH] Added file type path to file manager response --- src/octoprint/filemanager/storage.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index 610040dc..7552e5c1 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -81,10 +81,12 @@ class StorageInterface(object): "children": { "some_sub_folder": { "type": "folder", + "typePath": ["folder"], "children": { ... } }, "some_file.gcode": { "type": "machinecode", + "typePath": ["machinecode", "gcode"], "hash": "", "links": [ ... ], ... @@ -93,12 +95,14 @@ class StorageInterface(object): } "test.gcode": { "type": "machinecode", + "typePath": ["machinecode", "gcode"], "hash": "", "links": [...], ... }, "test.stl": { "type": "model", + "typePath": ["model", "stl"], "hash": "", "links": [...], ... @@ -1035,12 +1039,12 @@ class LocalFileStorage(StorageInterface): # file handling if os.path.isfile(entry_path): - file_type = octoprint.filemanager.get_file_type(entry) - if not file_type: + type_path = octoprint.filemanager.get_file_type(entry) + if not type_path: # only supported extensions continue else: - file_type = file_type[0] + file_type = type_path[0] if entry in metadata and isinstance(metadata[entry], dict): entry_data = metadata[entry] @@ -1056,6 +1060,7 @@ class LocalFileStorage(StorageInterface): extended_entry_data.update(entry_data) extended_entry_data["name"] = entry extended_entry_data["type"] = file_type + extended_entry_data["typePath"] = type_path stat = os.stat(entry_path) if stat: extended_entry_data["size"] = stat.st_size @@ -1069,13 +1074,14 @@ class LocalFileStorage(StorageInterface): entry_data = dict( name=entry, type="folder", + type_path=["folder"], children=sub_result ) if not filter or filter(entry, entry_data): def get_size(): total_size = 0 - for element in entry_data["children"].itervalues(): + for element in entry_data["children"].values(): if "size" in element: total_size += element["size"]