show folder size.

This commit is contained in:
Yoshihiro OKUMURA 2023-12-18 16:59:53 +09:00
parent 64f64b82dc
commit a281a97b3e
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2
2 changed files with 8 additions and 5 deletions

View File

@ -82,7 +82,7 @@ class LsCommand(BaseCommand):
"type": "Type", "type": "Type",
"acl": "Access", "acl": "Access",
"laboratory": "Laboratory", "laboratory": "Laboratory",
"size": "Lock/Size", "size": "Size",
"date": "Date", "date": "Date",
"name": "Name", "name": "Name",
} }
@ -94,7 +94,7 @@ class LsCommand(BaseCommand):
sub_laboratory_name = sub_laboratory.name if sub_laboratory is not None else "(invalid)" sub_laboratory_name = sub_laboratory.name if sub_laboratory is not None else "(invalid)"
length["acl"] = max(length["acl"], len(sub_folder.access_level_name)) length["acl"] = max(length["acl"], len(sub_folder.access_level_name))
length["laboratory"] = max(length["laboratory"], len(sub_laboratory_name)) length["laboratory"] = max(length["laboratory"], len(sub_laboratory_name))
length["size"] = max(length["size"], len(sub_folder.lock_name)) length["size"] = max(length["size"], len(str(folder.size)))
length["date"] = max(length["date"], len(sub_folder.updated_at_name)) length["date"] = max(length["date"], len(sub_folder.updated_at_name))
length["name"] = max(length["name"], len(sub_folder.name)) length["name"] = max(length["name"], len(sub_folder.name))
for file in folder.files: for file in folder.files:
@ -119,9 +119,10 @@ class LsCommand(BaseCommand):
for sub_folder in sorted(folder.sub_folders, key=lambda x: x.name): for sub_folder in sorted(folder.sub_folders, key=lambda x: x.name):
sub_laboratory_name = cls._laboratory_name(context, sub_folder.laboratory_id) sub_laboratory_name = cls._laboratory_name(context, sub_folder.laboratory_id)
sub_folder_type = "[d]" if sub_folder.lock is False else "[l]"
print( print(
f"{'[d]':{length['type']}}\t{sub_folder.access_level_name:{length['acl']}}\t" f"{sub_folder_type:{length['type']}}\t{sub_folder.access_level_name:{length['acl']}}\t"
f"{sub_laboratory_name:{length['laboratory']}}\t{sub_folder.lock_name:{length['size']}}\t" f"{sub_laboratory_name:{length['laboratory']}}\t{sub_folder.size:{length['size']}}\t"
f"{sub_folder.updated_at_name:{length['date']}}\t{sub_folder.name:{length['name']}}" f"{sub_folder.updated_at_name:{length['date']}}\t{sub_folder.name:{length['name']}}"
) )
for file in sorted(folder.files, key=lambda x: x.name): for file in sorted(folder.files, key=lambda x: x.name):
@ -149,6 +150,7 @@ class LsCommand(BaseCommand):
"id": folder.id, "id": folder.id,
"pid": folder.pid, "pid": folder.pid,
"name": folder.name, "name": folder.name,
"size": folder.size,
"access_level": folder.access_level_name, "access_level": folder.access_level_name,
"lock": folder.lock, "lock": folder.lock,
"laboratory": cls._laboratory_name(context, folder.laboratory_id), "laboratory": cls._laboratory_name(context, folder.laboratory_id),

View File

@ -15,7 +15,7 @@ class FolderAccessLevelItem(NamedTuple):
class FolderAccessLevel: class FolderAccessLevel:
# Bit Mask # Bit Mask
# - bit 0: Storage or Repository # - bit 0: Is Private
# - bit 1: Is Public # - bit 1: Is Public
# - bit 2: With Password # - bit 2: With Password
# - bit 3-7: (Reserved) # - bit 3-7: (Reserved)
@ -49,6 +49,7 @@ class FolderSimple:
name: str name: str
access_level: int access_level: int
lock: bool lock: bool
size: int
laboratory_id: int laboratory_id: int
description: str description: str
created_at: str created_at: str