Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added item_count #1492

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added item_count
Rishab87 committed Jan 21, 2025
commit 1547abb2eeb56da5d29920349611c71adae370b8
7 changes: 6 additions & 1 deletion jupyter_server/services/contents/filemanager.py
Original file line number Diff line number Diff line change
@@ -293,9 +293,12 @@ def _dir_model(self, path, content=True):
model = self._base_model(path)
model["type"] = "directory"
model["size"] = None
model["item_count"] = None
if content:
model["content"] = contents = []
os_dir = self._get_os_path(path)
dir_contents = os.listdir(os_dir)
model["item_count"] = len(dir_contents)
for name in os.listdir(os_dir):
try:
os_path = os.path.join(os_dir, name)
@@ -334,7 +337,6 @@ def _dir_model(self, path, content=True):
os_path,
exc_info=True,
)

model["format"] = "json"

return model
@@ -470,6 +472,7 @@ def _save_directory(self, os_path, model, path=""):
if not os.path.exists(os_path):
with self.perm_to_403():
os.mkdir(os_path)
model["item_count"] = 0
elif not os.path.isdir(os_path):
raise web.HTTPError(400, "Not a directory: %s" % (os_path))
else:
@@ -765,10 +768,12 @@ async def _dir_model(self, path, content=True):
model = self._base_model(path)
model["type"] = "directory"
model["size"] = None
model["item_count"] = None
if content:
model["content"] = contents = []
os_dir = self._get_os_path(path)
dir_contents = await run_sync(os.listdir, os_dir)
model["item_count"] = len(dir_contents)
for name in dir_contents:
try:
os_path = os.path.join(os_dir, name)