tree aggregate on find

This commit is contained in:
Amber 2024-01-30 20:53:27 +01:00
parent de88767812
commit c16788d90b
6 changed files with 33 additions and 5 deletions

Binary file not shown.

View File

@ -76,19 +76,24 @@ class NerdTree():
## rootnode for definition is always a folder
rootnode = tosplit.split('/')[-1]
stat_dir_item = os.stat(startpath)
# stat_dir_item = os.stat(startpath)
# start_dir_item_type is always 'd'
start_dir_item_type, start_dir_object = self.get_path_obj(startpath)
stat_dir_item = start_dir_object.lstat()
if path:
path.append({
'name' : rootnode,
'type' : 'd',
'type' : start_dir_item_type,
'abs_path' : startpath,
'size' : stat_dir_item.st_size,
})
else:
path = [{
'name' : './',
'type' : 'd',
'type' : start_dir_item_type,
'abs_path' : startpath,
'size' : stat_dir_item.st_size,
}]
d = {
@ -162,7 +167,7 @@ class NerdTree():
}
## if you want count the current directory as item you must sum 1
## if you want count the current directory size you must include item['size']
subtree['subtree_size'] += subtree_compute['subtree_size'] + item['subtree_size']
subtree['subtree_size'] += subtree_compute['subtree_size'] + item['size']
subtree['subtree_items'] += subtree_compute['subtree_items'] + 1
else:
subtree['subtree_size'] += item['size']
@ -188,7 +193,8 @@ class NerdTree():
nodefound = rootnode.get('found')
if nodefound and self.opts['dont_show_children_nodes']:
if rootnode.get('subtree_items'):
nerd_tree_txt += ' (%s item(s)/%s %s ▾)' % (rootnode['subtree_items'], rootnode['subtree_size'], 'b')
hnum, unit = _tree_repr.format(rootnode['subtree_size'])
nerd_tree_txt += ' (%s item(s)/%s%s ▾)' % (rootnode['subtree_items'], hnum, unit)
# return nerd_tree_txt
# else:
# nerd_tree_txt += ' (0 - 0 ▾)'

View File

@ -107,6 +107,7 @@ class NerdTreeFind(NerdTree):
if not islastpath: children.append(pcopy)
else : children.append(node)
# key size is lost in preceding code!!!!!!!!!!!!
self.compute_aggregate_recursively(tree_struct)
return tree_struct

View File

@ -13,6 +13,10 @@ LAST_CHILD_CONNECTOR = '└── '
LEVEL_INDENT = 4
ITEMS_TO_EXCLUDE = ['__pycache__']
KB = 1024
MB = 1024*1024
GB = 1024*1024*1024
def mount_str_at(source_str, index, mount_str):
l = len(mount_str)
return source_str[:index] + mount_str + source_str[index+l:]
@ -46,3 +50,20 @@ 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:
# unit = 'b'
# human_number = num
unit = 'b'
human_number = num
return human_number, unit