Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,4 @@ _Empty sprint_
## 2025-11-10 - 2025-11-21

- Add legacy-cgi dependency ([#857](https://github.com/ScilifelabDataCentre/dds_cli/pull/857))
- Fix combine --size and --tree bug([#858](https://github.com/ScilifelabDataCentre/dds_cli/pull/858))
43 changes: 20 additions & 23 deletions dds_cli/data_lister.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@
###############################################################################

# Standard library
from dataclasses import dataclass
import logging
from typing import Tuple, Union, List
import datetime
import logging
import pathlib
from dataclasses import dataclass
from typing import List, Tuple, Union

# Installed
from rich.padding import Padding
import pytz
import tzlocal
from rich.markup import escape
from rich.padding import Padding
from rich.table import Table
from rich.tree import Tree
import pytz
import tzlocal

# Own modules
from dds_cli import base
from dds_cli import exceptions
import dds_cli.utils
from dds_cli import DDSEndpoint
from dds_cli import DDSEndpoint, base, exceptions
from dds_cli import text_handler as th
import dds_cli.utils


###############################################################################
Expand Down Expand Up @@ -268,7 +266,11 @@ def __construct_file_tree(folder: str, basename: str) -> Tuple[FileTree, int, in
# Get max length of size string
max_size = max(
(
len(x["size"].split(" ")[0])
len(
dds_cli.utils.format_api_response(
response=x["size"], key="Size", binary=self.binary
).split(" ", maxsplit=1)[0]
)
for x in sorted_files_folders
if show_size and "size" in x
),
Expand All @@ -280,9 +282,12 @@ def __construct_file_tree(folder: str, basename: str) -> Tuple[FileTree, int, in
is_folder = item.pop("folder")

if not is_folder:
tree.subtrees.append(
(escape(item["name"]), item.get("size") if show_size else None)
)
formatted_size = None
if show_size and "size" in item:
formatted_size = dds_cli.utils.format_api_response(
response=item["size"], key="Size", binary=self.binary
)
tree.subtrees.append((escape(item["name"]), formatted_size))
else:
subtree, _max_string, _max_size = __construct_file_tree(
pathlib.Path(folder, item["name"]).as_posix() if folder else item["name"],
Expand Down Expand Up @@ -348,15 +353,7 @@ def __construct_rich_tree(
string_len=len(node[0]),
max_string_len=max_str - 4 * depth,
)
line += f"{tab}{node[1].split()[0]}"

# Define space between number and size format
tabs_bf_format = th.TextHandler.format_tabs(
string_len=len(node[1].split()[1]),
max_string_len=max_size,
tab_len=2,
)
line += f"{tabs_bf_format}{node[1].split()[1]}"
line += f"{tab}{node[1].split()[0]} {node[1].split()[1]}"
tree.add(line)

return tree, tree_length
Expand Down
Loading