tree aggregate on find
This commit is contained in:
parent
de88767812
commit
c16788d90b
Binary file not shown.
Binary file not shown.
Binary file not shown.
16
src/tree.py
16
src/tree.py
|
@ -76,19 +76,24 @@ class NerdTree():
|
||||||
## rootnode for definition is always a folder
|
## rootnode for definition is always a folder
|
||||||
rootnode = tosplit.split('/')[-1]
|
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:
|
if path:
|
||||||
path.append({
|
path.append({
|
||||||
'name' : rootnode,
|
'name' : rootnode,
|
||||||
'type' : 'd',
|
'type' : start_dir_item_type,
|
||||||
'abs_path' : startpath,
|
'abs_path' : startpath,
|
||||||
|
'size' : stat_dir_item.st_size,
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
path = [{
|
path = [{
|
||||||
'name' : './',
|
'name' : './',
|
||||||
'type' : 'd',
|
'type' : start_dir_item_type,
|
||||||
'abs_path' : startpath,
|
'abs_path' : startpath,
|
||||||
|
'size' : stat_dir_item.st_size,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
d = {
|
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 as item you must sum 1
|
||||||
## if you want count the current directory size you must include item['size']
|
## 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
|
subtree['subtree_items'] += subtree_compute['subtree_items'] + 1
|
||||||
else:
|
else:
|
||||||
subtree['subtree_size'] += item['size']
|
subtree['subtree_size'] += item['size']
|
||||||
|
@ -188,7 +193,8 @@ class NerdTree():
|
||||||
nodefound = rootnode.get('found')
|
nodefound = rootnode.get('found')
|
||||||
if nodefound and self.opts['dont_show_children_nodes']:
|
if nodefound and self.opts['dont_show_children_nodes']:
|
||||||
if rootnode.get('subtree_items'):
|
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
|
# return nerd_tree_txt
|
||||||
# else:
|
# else:
|
||||||
# nerd_tree_txt += ' (0 - 0 ▾)'
|
# nerd_tree_txt += ' (0 - 0 ▾)'
|
||||||
|
|
|
@ -107,6 +107,7 @@ class NerdTreeFind(NerdTree):
|
||||||
if not islastpath: children.append(pcopy)
|
if not islastpath: children.append(pcopy)
|
||||||
else : children.append(node)
|
else : children.append(node)
|
||||||
|
|
||||||
|
# key size is lost in preceding code!!!!!!!!!!!!
|
||||||
self.compute_aggregate_recursively(tree_struct)
|
self.compute_aggregate_recursively(tree_struct)
|
||||||
return tree_struct
|
return tree_struct
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@ LAST_CHILD_CONNECTOR = '└── '
|
||||||
LEVEL_INDENT = 4
|
LEVEL_INDENT = 4
|
||||||
ITEMS_TO_EXCLUDE = ['__pycache__']
|
ITEMS_TO_EXCLUDE = ['__pycache__']
|
||||||
|
|
||||||
|
KB = 1024
|
||||||
|
MB = 1024*1024
|
||||||
|
GB = 1024*1024*1024
|
||||||
|
|
||||||
def mount_str_at(source_str, index, mount_str):
|
def mount_str_at(source_str, index, mount_str):
|
||||||
l = len(mount_str)
|
l = len(mount_str)
|
||||||
return source_str[:index] + mount_str + source_str[index+l:]
|
return source_str[:index] + mount_str + source_str[index+l:]
|
||||||
|
@ -46,3 +50,20 @@ def produce_treeline(prec_seps, lsep):
|
||||||
|
|
||||||
return tree_line.rstrip()
|
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
|
||||||
|
|
Loading…
Reference in New Issue