diff --git a/docs/api/datamodel.rst b/docs/api/datamodel.rst index 74d56dc57..9c423adc1 100644 --- a/docs/api/datamodel.rst +++ b/docs/api/datamodel.rst @@ -280,13 +280,12 @@ Folders * - ``children`` - 0..* - Array of :ref:`File information items ` - - Contained children for entries of type ``folder``. Will only include children in subfolders in recursive - listings. Not present in non recursive listings, this might be revisited in the future. + - Contained children for entries of type ``folder``. On non recursive listings only present on first level + sub folders! * - ``size`` - 0..1 - Number - - The size of all files contained in the folder and its subfolders. Not present in non recursive listings, this might - be revisited in the future. + - The size of all files contained in the folder and its subfolders. Not present in non recursive listings! Files ''''' diff --git a/docs/api/files.rst b/docs/api/files.rst index 188731a40..b13123036 100644 --- a/docs/api/files.rst +++ b/docs/api/files.rst @@ -82,8 +82,37 @@ Retrieve all files "path": "folderA", "type": "folder", "typePath": ["folder"], - "children": [], - "size": 1334 + "children": [ + { + "name": "whistle_v2_copy.gcode", + "path": "whistle_v2_copy.gcode", + "type": "machinecode", + "typePath": ["machinecode", "gcode"], + "hash": "...", + "size": 1468987, + "date": 1378847754, + "origin": "local", + "refs": { + "resource": "http://example.com/api/files/local/folderA/whistle_v2_copy.gcode", + "download": "http://example.com/downloads/files/local/folderA/whistle_v2_copy.gcode" + }, + "gcodeAnalysis": { + "estimatedPrintTime": 1188, + "filament": { + "length": 810, + "volume": 5.36 + } + }, + "print": { + "failure": 4, + "success": 23, + "last": { + "date": 1387144346, + "success": true + } + } + } + ] } ], "free": "3.2GB" diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index dc4e9f16b..de1b43072 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -153,7 +153,8 @@ class StorageInterface(object): from root of base folder :param function filter: a filter that matches the files that are to be returned, may be left out in which case no filtering will take place - :param bool recursive: will also step into sub folders for building the complete list if set to True + :param bool recursive: will also step into sub folders for building the complete list if set to True, otherwise will only + do one step down into sub folders to be able to populate the ``children``. :return: a dictionary mapping entry names to entry data that represents the whole file list """ raise NotImplementedError() @@ -1277,7 +1278,7 @@ class LocalFileStorage(StorageInterface): if metadata_dirty: self._save_metadata(path, metadata) - def _list_folder(self, path, base="", entry_filter=None, recursive=True, **kwargs): + def _list_folder(self, path, base="", entry_filter=None, recursive=True, include_children=True, **kwargs): if entry_filter is None: entry_filter = kwargs.get("filter", None) @@ -1385,8 +1386,14 @@ class LocalFileStorage(StorageInterface): sub_result = self._list_folder(entry_path, base=path_in_location + "/", entry_filter=entry_filter, recursive=recursive) entry_data["children"] = sub_result + elif include_children: + sub_result = self._list_folder(entry_path, base=path_in_location + "/", entry_filter=entry_filter, + recursive=False, include_children=False) + entry_data["children"] = sub_result if not entry_filter or entry_filter(entry_name, entry_data): + # only add folders passing the optional filter + def get_size(): total_size = 0 for element in entry_data["children"].values(): @@ -1395,7 +1402,6 @@ class LocalFileStorage(StorageInterface): return total_size - # only add folders passing the optional filter extended_entry_data = dict() extended_entry_data.update(entry_data) if recursive: