diff --git a/src/__pycache__/tree.cpython-39.pyc b/src/__pycache__/tree.cpython-39.pyc index cc2e19b..f091709 100644 Binary files a/src/__pycache__/tree.cpython-39.pyc and b/src/__pycache__/tree.cpython-39.pyc differ diff --git a/src/__pycache__/tree_find.cpython-39.pyc b/src/__pycache__/tree_find.cpython-39.pyc index 177a252..6ac9c4f 100644 Binary files a/src/__pycache__/tree_find.cpython-39.pyc and b/src/__pycache__/tree_find.cpython-39.pyc differ diff --git a/src/__pycache__/tree_repr.cpython-39.pyc b/src/__pycache__/tree_repr.cpython-39.pyc index c2fe514..2dec306 100644 Binary files a/src/__pycache__/tree_repr.cpython-39.pyc and b/src/__pycache__/tree_repr.cpython-39.pyc differ diff --git a/src/tree.py b/src/tree.py index da97e72..a231e92 100644 --- a/src/tree.py +++ b/src/tree.py @@ -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 ▾)' diff --git a/src/tree_find.py b/src/tree_find.py index dded9d2..988457a 100644 --- a/src/tree_find.py +++ b/src/tree_find.py @@ -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 diff --git a/src/tree_repr.py b/src/tree_repr.py index 94877f8..f79be37 100644 --- a/src/tree_repr.py +++ b/src/tree_repr.py @@ -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