Skip to content

Commit cba70e0

Browse files
committed
du: fix priority sort
1 parent c392b3a commit cba70e0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

library/fsdb/disk_usage.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ def parse_args(defaults_override=None):
5050

5151
def sort_by(args):
5252
if args.sort_groups_by:
53-
return lambda x: x.get(args.sort_groups_by.replace(" desc", "")) or 0
53+
key = args.sort_groups_by.replace(" desc", "")
54+
if key != "priority":
55+
return lambda x: (x.get(key) or 0, objects.Reverser(x.get("path")))
5456

57+
# priority sort
5558
return lambda x: (
56-
x.get("size") or 0 / (x.get("count") or 1),
59+
(x.get("size") or 0) / (x.get("count") or 1),
5760
x.get("size") or 0,
5861
x.get("count") or 1,
62+
x.get("folders") or 1,
5963
objects.Reverser(x.get("path")),
6064
)
6165

library/usage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def play(action) -> str:
649649
library big-dirs ./video/ -u 'mcda median_size,-deleted'
650650
"""
651651

652-
disk_usage = """library disk-usage DATABASE [--sort-groups-by size | count] [--depth DEPTH] [PATH / SUBSTRING SEARCH]
652+
disk_usage = """library disk-usage DATABASE [--sort-groups-by (priority) | path | size | count] [--depth DEPTH] [PATH / SUBSTRING SEARCH]
653653
654654
To aggregate to high level folders use --parents and --depth
655655

0 commit comments

Comments
 (0)