human number representation

This commit is contained in:
Amber 2024-01-31 12:01:46 +01:00
parent 179b2ab3f9
commit 8e174308a3
1 changed files with 16 additions and 15 deletions

View File

@ -11,7 +11,8 @@ CHILD_CONNECTOR = '├── '
LAST_CHILD_CONNECTOR = '└── '
### is the length of child connector and last_child_connector
LEVEL_INDENT = 4
ITEMS_TO_EXCLUDE = ['__pycache__']
# ITEMS_TO_EXCLUDE = ['__pycache__']
ITEMS_TO_EXCLUDE = []
KB = 1024
MB = 1024*1024
@ -51,19 +52,19 @@ def produce_treeline(prec_seps, lsep):
return tree_line.rstrip()
def format(num, unit=None):
# if num/GB >=1:
# unit = 'GB'
# human_number = round(num/GB, 2)
# elif num/MB >=1:
# unit = 'MB'
# human_number = round(num/MB, 2)
# elif num/KB >=1:
# unit = 'kB'
# human_number = round(num/KB, 2)
# else:
if num/GB >=1 or unit == 'G':
unit = 'G'
human_number = round(num/GB, 2)
elif num/MB >=1 or unit == 'M':
unit = 'M'
human_number = round(num/MB, 2)
elif num/KB >=1 or unit == 'K':
unit = 'K'
human_number = round(num/KB, 2)
else:
unit = 'B'
human_number = num
# unit = 'b'
# human_number = num
unit = 'b'
human_number = num
return human_number, unit