mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-02 15:08:11 +08:00
Exclude directories having no h5ad files
This commit is contained in:
@@ -63,7 +63,7 @@ class FileItemSource(ItemSource):
|
||||
|
||||
return item_tree
|
||||
|
||||
def scan_directory(self, subpath="") -> dict:
|
||||
def scan_directory(self, subpath: str = "") -> ItemTree:
|
||||
base_path = os.path.join(self.base_path, subpath)
|
||||
|
||||
if not os.path.exists(base_path):
|
||||
@@ -100,6 +100,9 @@ class FileItemSource(ItemSource):
|
||||
branches = [
|
||||
self.scan_directory(os.path.join(subpath, subdir)) for subdir in subdirs
|
||||
]
|
||||
# Exclude branches without files as leaves. Since traversal is applied pre-order,
|
||||
# branch.branches has already been processed and we don't need to check deeper nesting.
|
||||
branches = [branch for branch in branches if branch.items or branch.branches]
|
||||
|
||||
return ItemTree(subpath, items, branches)
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@ class S3ItemSource(ItemSource):
|
||||
branches = None
|
||||
if len(subdir_keys) > 0:
|
||||
branches = [self.scan_directory(key) for key in subdir_keys]
|
||||
branches = [branch for branch in branches if branch.items or branch.branches]
|
||||
|
||||
return ItemTree(directory_key, items, branches)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user